code: def downscale_image(im, max_dim=2048):
      """Shrink im until its longest dimension is <= max_dim.
      Returns new_image, scale (where scale <= 1)."""
      a, b = im.shape[:2]
      if max(a, b) <= max_dim:
          return 1.0, im
  
      scale = 1.0 * max_dim / max(a, b)
      new_im = cv2.resize(
          im, (int(b * scale), int(a * scale)), cv2.INTER_AREA
      )
      return scale, new_im
  
imports: import os
  import traceback
  import sys
  import cv2
  import numpy
  from PIL import Image
  from scipy.ndimage.filters import rank_filter
  import pytesseract
label_desc: Use image node_id 3 for calling a global function with example usage: downscale_image(im, max_dim) and returns: scale,  new_im, int,  im