code: def imsavetoblob(img, filetype, flags=0):
      """
      s = imsavetoblob(img, filetype, flags=0)
  
      Save `img` to a `str` object
  
      Parameters
      ----------
      img : ndarray
          input image
      filetype : str or integer
          A file name like string, used only to determine the file type.
          Alternatively, an integer flag (from FI_FORMAT).
      flags : integer, optional
  
      Returns
      -------
      s : str
          byte representation of `img` in format `filetype`
      """
      if type(filetype) == str:
          ftype = _FI.FreeImage_GetFIFFromFilename(_bytestr(filetype))
      else:
          ftype = filetype
      try:
          bitmap, fi_type = _array_to_bitmap(img)
          mem = _FI.FreeImage_OpenMemory(0, 0)
          if not _FI.FreeImage_SaveToMemory(ftype, bitmap, mem, flags):
              raise IOError(
                  "mahotas.freeimage.imsavetoblob: Cannot save to memory."
              )
          data = ctypes.c_void_p()
          size = ctypes.c_int()
          _FI.FreeImage_AcquireMemory(
              mem, ctypes.byref(data), ctypes.byref(size)
          )
          return ctypes.string_at(data, size)
      finally:
          _FI.FreeImage_CloseMemory(mem)
  
imports: import sys
  import os
  import ctypes
  import ctypes.util
  import numpy
label_desc: Use image node_id 12 for calling a global function with example usage: imsavetoblob(img, filetype, flags) and returns: ctypes