code: def fromqimage(im):
      """
      :param im: QImage or PIL ImageQt object
      """
      buffer = QBuffer()
      if qt_version == "6":
          try:
              qt_openmode = QIODevice.OpenModeFlag
          except AttributeError:
              qt_openmode = QIODevice.OpenMode
      else:
          qt_openmode = QIODevice
      buffer.open(qt_openmode.ReadWrite)
      # preserve alpha channel with png
      # otherwise ppm is more friendly with Image.open
      if im.hasAlphaChannel():
          im.save(buffer, "png")
      else:
          im.save(buffer, "ppm")
  
      b = BytesIO()
      b.write(buffer.data())
      buffer.close()
      b.seek(0)
  
      return Image.open(b)
  
file_path: pillow-simd/src/PIL/ImageQt.py
imports: import sys
  from io import BytesIO
  from .None import Image
  from ._util import isPath
label_desc: Use image node_id 2 for calling a global function with example usage: fromqimage(im) and returns: Image