code: def fit(
      image, size, method=Image.NEAREST, bleed=0.0, centering=(0.5, 0.5)
  ):
      """
      Returns a sized and cropped version of the image, cropped to the
      requested aspect ratio and size.
  
      This function was contributed by Kevin Cazabon.
  
      :param image: The image to size and crop.
      :param size: The requested output size in pixels, given as a
                   (width, height) tuple.
      :param method: What resampling method to use. Default is
                     :py:attr:`PIL.Image.NEAREST`.
      :param bleed: Remove a border around the outside of the image from all
                    four edges. The value is a decimal percentage (use 0.01 for
                    one percent). The default value is 0 (no border).
                    Cannot be greater than or equal to 0.5.
      :param centering: Control the cropping position.  Use (0.5, 0.5) for
                        center cropping (e.g. if cropping the width, take 50% off
                        of the left side, and therefore 50% off the right side).
                        (0.0, 0.0) will crop from the top left corner (i.e. if
                        cropping the width, take all of the crop off of the right
                        side, and if cropping the height, take all of it off the
                        bottom).  (1.0, 0.0) will crop from the bottom left
                        corner, etc. (i.e. if cropping the width, take all of the
                        crop off the left side, and if cropping the height take
                        none from the top, and therefore all off the bottom).
      :return: An image.
      """
  
      # by Kevin Cazabon, Feb 17/2000
      # kevin@cazabon.com
      # http://www.cazabon.com
  
      # ensure centering is mutable
      centering = list(centering)
  
      if not 0.0 <= centering[0] <= 1.0:
          centering[0] = 0.5
      if not 0.0 <= centering[1] <= 1.0:
          centering[1] = 0.5
  
      if not 0.0 <= bleed < 0.5:
          bleed = 0.0
  
      # calculate the area to use for resizing and cropping, subtracting
      # the 'bleed' around the edges
  
      # number of pixels to trim off on Top and Bottom, Left and Right
      bleed_pixels = (bleed * image.size[0], bleed * image.size[1])
  
      live_size = (
          image.size[0] - bleed_pixels[0] * 2,
          image.size[1] - bleed_pixels[1] * 2,
      )
  
      # calculate the aspect ratio of the live_size
      live_size_ratio = float(live_size[0]) / live_size[1]
  
      # calculate the aspect ratio of the output image
      output_ratio = float(size[0]) / size[1]
  
      # figure out if the sides or top/bottom will be cropped off
      if live_size_ratio == output_ratio:
          # live_size is already the needed ratio
          crop_width = live_size[0]
          crop_height = live_size[1]
      elif live_size_ratio >= output_ratio:
          # live_size is wider than what's needed, crop the sides
          crop_width = output_ratio * live_size[1]
          crop_height = live_size[1]
      else:
          # live_size is taller than what's needed, crop the top and bottom
          crop_width = live_size[0]
          crop_height = live_size[0] / output_ratio
  
      # make the crop
      crop_left = (
          bleed_pixels[0] + (live_size[0] - crop_width) * centering[0]
      )
      crop_top = (
          bleed_pixels[1] + (live_size[1] - crop_height) * centering[1]
      )
  
      crop = (
          crop_left,
          crop_top,
          crop_left + crop_width,
          crop_top + crop_height,
      )
  
      # resize the image and return it
      return image.resize(size, method, box=crop)
  
imports: import functools
  import operator
  from .None import Image
  from ._util import isStringType
label_desc: Use image node_id 12 for calling a global function with example usage: fit(image, size, method, bleed, centering) and returns: image