code: def write(array, filename, flags=0):
      """Write a (width, height) or (width, height, nchannels) array to
      a greyscale, RGB, or RGBA image, with file type deduced from the
      filename.
  
      """
      filename = _bytestr(filename)
      ftype = _FI.FreeImage_GetFIFFromFilename(filename)
      if ftype == -1:
          raise ValueError(
              "mahotas.freeimage: cannot determine type for %s"
              % filename
          )
      bitmap, fi_type = _array_to_bitmap(array)
      try:
          if fi_type == FI_TYPES.FIT_BITMAP:
              can_write = _FI.FreeImage_FIFSupportsExportBPP(
                  ftype, _FI.FreeImage_GetBPP(bitmap)
              )
          else:
              can_write = _FI.FreeImage_FIFSupportsExportType(
                  ftype, fi_type
              )
          if not can_write:
              raise TypeError(
                  "mahotas.freeimage: cannot save image of this type (%s) "
                  "to this file type" % array.dtype
              )
          res = _FI.FreeImage_Save(ftype, bitmap, filename, flags)
          if not res:
              raise RuntimeError(
                  "mahotas.freeimage: could not save image properly."
              )
      finally:
          _FI.FreeImage_Unload(bitmap)
  
imports: import sys
  import os
  import ctypes
  import ctypes.util
  import numpy
label_desc: Use image node_id 9 for calling a global function with example usage: write(array, filename, flags) without return types