code: def pil_to_blob(img):
      bytesio = io.BytesIO()
      if isinstance(img, PIL.PngImagePlugin.PngImageFile):
          img.save(bytesio, format="PNG")
          mime_type = "image/png"
      else:
          img.save(bytesio, format="JPEG")
          mime_type = "image/jpeg"
      bytesio.seek(0)
      data = bytesio.read()
      return glm.Blob(mime_type=mime_type, data=data)
  
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 1 for calling a global function with example usage: pil_to_blob(img) and returns: glm