code: def pad(
      image,
      size,
      method=Image.Resampling.BICUBIC,
      color=None,
      centering=(0.5, 0.5),
  ):
      """
      Returns a resized and padded version of the image, expanded to fill the
      requested aspect ratio and size.
  
      :param image: The image to resize and crop.
      :param size: The requested output size in pixels, given as a
                   (width, height) tuple.
      :param method: Resampling method to use. Default is
                     :py:attr:`~PIL.Image.Resampling.BICUBIC`.
                     See :ref:`concept-filters`.
      :param color: The background color of the padded image.
      :param centering: Control the position of the original image within the
                        padded version.
  
                            (0.5, 0.5) will keep the image centered
                            (0, 0) will keep the image aligned to the top left
                            (1, 1) will keep the image aligned to the bottom
                            right
      :return: An image.
      """
  
      resized = contain(image, size, method)
      if resized.size == size:
          out = resized
      else:
          out = Image.new(image.mode, size, color)
          if resized.palette:
              out.putpalette(resized.getpalette())
          if resized.width != size[0]:
              x = round(
                  (size[0] - resized.width)
                  * max(0, min(centering[0], 1))
              )
              out.paste(resized, (x, 0))
          else:
              y = round(
                  (size[1] - resized.height)
                  * max(0, min(centering[1], 1))
              )
              out.paste(resized, (0, y))
      return out
  
imports: import functools
  import operator
  import re
  from .None import ExifTags, Image, ImagePalette
label_desc: Use image node_id 8 for calling a global function with example usage: pad(image, size, method, color, centering) and returns: out