class_docstr: Creates an image component that can be used to upload and edit images (as an input) or display images (as an output).
  Preprocessing: passes the uploaded images as a dictionary with keys: `background`, `layers`, and `composite`. The values corresponding to `background` and `composite` are images, while `layers` is a list of images. The images are of type PIL.Image, np.array, or str filepath, depending on the `type` parameter.
  Postprocessing: expects a dictionary with keys: `background`, `layers`, and `composite`. The values corresponding to `background` and `composite` should be images or None, while `layers` should be a list of images. Images can be of type PIL.Image, np.array, or str filepath/URL. Or, the value can be simply a single image, in which case it will be used as the background.
  Examples-format: a dictionary with keys: `background`, `layers`, and `composite`. The values corresponding to `background` and `composite` should be strings or None, while `layers` should be a list of strings. The image corresponding to `composite`, if not None, is used as the example image. Otherwise, the image corresonding to `background` is used. The strings should be filepaths or URLs. Or, the value can be simply a single string filepath/URL to an image, which is used directly as the example image.
  Demos: image_editor
class_docstr_tok: ["Creates","an","image","component","that","can","be","used","to","upload","and","edit","images","(","as","an","input",")","or","display","images","(","as","an","output",")",".","Preprocessing",":","passes","the","uploaded","images","as","a","dictionary","with","keys",":","`","background","`",",","`","layers","`",",","and","`","composite","`",".","The","values","corresponding","to","`","background","`","and","`","composite","`","are","images",",","while","`","layers","`","is","a","list","of","images",".","The","images","are","of","type","PIL.Image",",","np.array",",","or","str","filepath",",","depending","on","the","`","type","`","parameter",".","Postprocessing",":","expects","a","dictionary","with","keys",":","`","background","`",",","`","layers","`",",","and","`","composite","`",".","The","values","corresponding","to","`","background","`","and","`","composite","`","should","be","images","or","None",",","while","`","layers","`","should","be","a","list","of","images",".","Images","can","be","of","type","PIL.Image",",","np.array",",","or","str","filepath\/URL",".","Or",",","the","value","can","be","simply","a","single","image",",","in","which","case","it","will","be","used","as","the","background",".","Examples-format",":","a","dictionary","with","keys",":","`","background","`",",","`","layers","`",",","and","`","composite","`",".","The","values","corresponding","to","`","background","`","and","`","composite","`","should","be","strings","or","None",",","while","`","layers","`","should","be","a","list","of","strings",".","The","image","corresponding","to","`","composite","`",",","if","not","None",",","is","used","as","the","example","image",".","Otherwise",",","the","image","corresonding","to","`","background","`","is","used",".","The","strings","should","be","filepaths","or","URLs",".","Or",",","the","value","can","be","simply","a","single","string","filepath\/URL","to","an","image",",","which","is","used","directly","as","the","example","image",".","Demos",":","image_editor"]
code: def convert_and_format_image(
      self,
      file: FileData | None,
  ) -> np.ndarray | _Image.Image | str | None:
      if file is None:
          return None
  
      im = _Image.open(file.path)
  
      if file.orig_name:
          p = Path(file.orig_name)
          name = p.stem
          suffix = p.suffix.replace(".", "")
          if suffix in ["jpg", "jpeg"]:
              suffix = "jpeg"
      else:
          name = "image"
          suffix = "png"
      with warnings.catch_warnings():
          warnings.simplefilter("ignore")
          im = im.convert(self.image_mode)
      if self.crop_size and not isinstance(self.crop_size, str):
          im = image_utils.crop_scale(
              im, int(self.crop_size[0]), int(self.crop_size[1])
          )
      return image_utils.format_image(
          im,
          cast(Literal["numpy", "pil", "filepath"], self.type),
          self.GRADIO_CACHE,
          format=suffix,
          name=name,
      )
  
imports: from __future__ import annotations
  import dataclasses
  import warnings
  from pathlib import Path
  from typing import Any, Iterable, List, Literal, Optional, TypedDict, Union, cast
  import numpy
  from gradio_client.documentation import document, set_documentation_group
  from PIL import Image
  import gradio.image_utils
  from gradio import utils
  from gradio.components.base import Component
  from gradio.data_classes import FileData, GradioModel
  from gradio.events import Events
label_desc: Use image node_id 2 for calling the ImageEditor obj's underlying member method code with example usage: obj.convert_and_format_image(file) and returns: image_utils, None