class_docstr: Converter for images
class_docstr_tok: ["Converter","for","images"]
docstr: Resize image to fit the new smaller size, retaining aspect ratio.
  
  We use the PIL thumbnail function, which guarantees the aspect ratio is
  maintained but does not ensure the output size matches your desired size
  (only that it will not exceed it). We then paste it onto a background image
  that matches the desired output size.
  
  If the new size is smaller than the original image size (in either
  dimension), the image is reduced so it's just large enough to fit the
  desired size, and padded with a background to ensure it's exactly the
  desired size.
  
  If the new size is larger than the original image size, the original size
  is retained and the image is padded with a background to make it exactly
  the desired size.
  
  Args:
    orig_img: PIL Image object.
  
  Returns:
    Void.
docstr_tok: ["Resize","image","to","fit","the","new","smaller","size",",","retaining","aspect","ratio",".","We","use","the","PIL","thumbnail","function",",","which","guarantees","the","aspect","ratio","is","maintained","but","does","not","ensure","the","output","size","matches","your","desired","size","(","only","that","it","will","not","exceed","it",")",".","We","then","paste","it","onto","a","background","image","that","matches","the","desired","output","size",".","If","the","new","size","is","smaller","than","the","original","image","size","(","in","either","dimension",")",",","the","image","is","reduced","so","it","'s","just","large","enough","to","fit","the","desired","size",",","and","padded","with","a","background","to","ensure","it","'s","exactly","the","desired","size",".","If","the","new","size","is","larger","than","the","original","image","size",",","the","original","size","is","retained","and","the","image","is","padded","with","a","background","to","make","it","exactly","the","desired","size",".","Args",":","orig_img",":","PIL","Image","object",".","Returns",":","Void","."]
code: def _resize_thumbnail_keep_aspect_ratio(self):
      """Resize image to fit the new smaller size, retaining aspect ratio.
  
      We use the PIL thumbnail function, which guarantees the aspect ratio is
      maintained but does not ensure the output size matches your desired size
      (only that it will not exceed it). We then paste it onto a background image
      that matches the desired output size.
  
      If the new size is smaller than the original image size (in either
      dimension), the image is reduced so it's just large enough to fit the
      desired size, and padded with a background to ensure it's exactly the
      desired size.
  
      If the new size is larger than the original image size, the original size
      is retained and the image is padded with a background to make it exactly
      the desired size.
  
      Args:
        orig_img: PIL Image object.
  
      Returns:
        Void.
      """
  
      # We use Image.ANTIALIAS for better quality. This is the recommended PIL
      # setting.
      self._orig_img.thumbnail(self._desired_size, Image.ANTIALIAS)
  
      offset = (
          int(
              round(
                  (self._desired_size[0] - self._orig_img.size[0])
                  * self._position[0]
              )
          ),
          int(
              round(
                  (self._desired_size[1] - self._orig_img.size[1])
                  * self._position[1]
              )
          ),
      )
  
      bkgd_img = Image.new(
          self._bg_mode, self._desired_size, self._bg_color
      )
      bkgd_img.paste(self._orig_img, offset)
      return bkgd_img
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from absl import logging
  from PIL import Image
  from PIL import ImageOps
label_desc: Use image node_id 3 for calling the ImageConverter obj's underlying member method code with example usage: obj._resize_thumbnail_keep_aspect_ratio() and returns: bkgd_img