code: def fit(
      image,
      width: int,
      height: int,
      cval: int = 255,
      mode="letterbox",
      return_scale=False,
  ):
      """Obtain a new image, fit to the specified size.
  
      Args:
          image: The input image
          width: The new width
          height: The new height
          cval: The constant value to use to fill the remaining areas of
              the image
          return_scale: Whether to return the scale used for the image
  
      Returns:
          The new image
      """
      fitted = None
      x_scale = width / image.shape[1]
      y_scale = height / image.shape[0]
      if x_scale == 1 and y_scale == 1:
          fitted = image
          scale = 1
      elif (x_scale <= y_scale and mode == "letterbox") or (
          x_scale >= y_scale and mode == "crop"
      ):
          scale = width / image.shape[1]
          resize_width = width
          resize_height = (width / image.shape[1]) * image.shape[0]
      else:
          scale = height / image.shape[0]
          resize_height = height
          resize_width = scale * image.shape[1]
      if fitted is None:
          resize_width, resize_height = map(
              int, [resize_width, resize_height]
          )
          if mode == "letterbox":
              fitted = (
                  np.zeros((height, width, 3), dtype="uint8") + cval
              )
              image = cv2.resize(
                  image, dsize=(resize_width, resize_height)
              )
              fitted[: image.shape[0], : image.shape[1]] = image[
                  :height, :width
              ]
          elif mode == "crop":
              image = cv2.resize(
                  image, dsize=(resize_width, resize_height)
              )
              fitted = image[:height, :width]
          else:
              raise NotImplementedError(f"Unsupported mode: {mode}")
      if not return_scale:
          return fitted
      return fitted, scale
  
imports: import os
  import io
  import typing
  import hashlib
  import urllib.request
  import urllib.parse
  import cv2
  import imgaug
  import numpy
  import validators
  import typing_extensions
  import matplotlib.pyplot
  from shapely import geometry
  from scipy import spatial
label_desc: Use image node_id 12 for calling a global function with example usage: fit(image, width, height, cval, mode, return_scale) and returns: fitted,  scale, fitted