code: def image_to_blob(image) -> glm.Blob:
      if PIL is not None:
          if isinstance(image, PIL.Image.Image):
              return pil_to_blob(image)
  
      if IPython is not None:
          if isinstance(image, IPython.display.Image):
              name = image.filename
              if name is None:
                  raise ValueError(
                      "Can only convert `IPython.display.Image` if "
                      "it is constructed from a local file (Image(filename=...))."
                  )
  
              mime_type, _ = mimetypes.guess_type(name)
              if mime_type is None:
                  mime_type = "image/unknown"
  
              return glm.Blob(mime_type=mime_type, data=image.data)
  
      raise TypeError(
          "Could not convert image. expected an `Image` type"
          "(`PIL.Image.Image` or `IPython.display.Image`).\n"
          f"Got a: {type(image)}\n"
          f"Value: {image}"
      )
  
imports: from __future__ import annotations
  from collections.abc import Iterable, Mapping
  import io
  import mimetypes
  import pathlib
  import typing
  from typing import Any, TypedDict, Union
  from google.ai import generativelanguage
label_desc: Use image node_id 2 for calling a global function with example usage: image_to_blob(image) and returns: pil_to_blob, glm