class_docstr: Image object used to store image objects in Aim repository...
  
  Args:
       image (:obj:): pillow `Image` object or `torch.Tensor` or `numpy.array` used to construct `aim.Image`.
       caption (:obj:`str`, optional): Optional image caption. '' by default.
       format (:obj:`str`, optional): Parameter for PIL's .save() method. 'png' by default.
       quality (:obj:`int`, optional): Parameter for PIL's .save() method. 90 by default.
       optimize (:obj:`bool`, optional): Parameter for PIL's .save() method. False by default.
  
       For more information on the format, quality and optimize parameters, refer to PIL documentation.
  
  Example of params to reduce quality of the image:
      format='jpeg',
      optimize=True,
      quality=85
code: def _from_pil_image(self, pil_image: PILImage.Image, params):
      assert isinstance(pil_image, PILImage.Image)
      img_container = BytesIO()
  
      if not params["format"]:
          params["format"] = pil_image.format or self.DEFAULT_IMG_FORMAT
      else:
          # normalize img format
          img_format = params["format"].lower()
          if img_format == "jpg":
              # PIL doesn't support 'jpg' key
              params["format"] = "jpeg"
          params["format"] = img_format
  
      if getattr(pil_image, "n_frames", 1) > 1:
          # is animated
          frames = PILImageSequence.all_frames(pil_image)
          params.update(
              dict(
                  save_all=True,
                  append_images=frames[1:],
              )
          )
          frames[0].save(img_container, **params)
      else:
          try:
              pil_image.save(img_container, **params)
          except OSError as exc:
              # The best way to approach this problem is to prepare PIL Image object before hitting this method.
              # This block only handles case where RGBA/P/LA/PA mode is mandated to save in RGB
              # PIL won't do that automatically, so we have to convert image to RGB before saving it.
              # In addition - make transparency "white" before conversion otherwise it will be black.
              if pil_image.mode not in ("RGBA", "LA", "PA", "P"):
                  raise exc
              elif not Image.FLAG_WARN_RGBA_RGB:
                  logger.warning(
                      f"Failed to save the image due to the following error: {exc}"
                  )
                  logger.warning(
                      f'Attempting to convert mode "{pil_image.mode}" to "RGB"'
                  )
                  Image.FLAG_WARN_RGBA_RGB = True
  
              alpha = pil_image.convert("RGBA").split()[
                  -1
              ]  # Get only alpha
              background = PILImage.new(
                  "RGBA", pil_image.size, (255, 255, 255, 255)
              )
              background.paste(pil_image, mask=alpha)
              pil_image = background.convert("RGB")
  
              # Retry
              pil_image.save(img_container, **params)
  
      self.storage["data"] = BLOB(data=img_container.getvalue())
      self.storage["source"] = "PIL.Image"
      self.storage["mode"] = pil_image.mode
      self.storage["format"] = params["format"]
      self.storage["width"], self.storage["height"] = pil_image.size
  
imports: import logging
  import os.path
  from PIL import Image, ImageSequence
  from io import BytesIO
  from itertools import chain, repeat
  from typing import List
  import numpy
  from aim.sdk.num_utils import inst_has_typename
  from aim.storage.object import CustomObject
  from aim.storage.types import BLOB
label_desc: Use image node_id 10 for calling the Image obj's underlying member method code with example usage: obj._from_pil_image(pil_image, params) without return types