code: def imsave(fname, arr, format_str=None, **kwargs):
      """Save an image to disk.
  
      Parameters
      ----------
      fname : str or file-like object
          Name of destination file.
      arr : ndarray of uint8 or float
          Array (image) to save.  Arrays of data-type uint8 should have
          values in [0, 255], whereas floating-point arrays must be
          in [0, 1].
      format_str: str
          Format to save as, this is defaulted to PNG if using a file-like
          object; this will be derived from the extension if fname is a string
      kwargs: dict
          Keyword arguments to the Pillow save function (or tifffile save
          function, for Tiff files). These are format dependent. For example,
          Pillow's JPEG save function supports an integer ``quality`` argument
          with values in [1, 95], while TIFFFile supports a ``compress``
          integer argument with values in [0, 9].
  
      Notes
      -----
      Use the Python Imaging Library.
      See PIL docs [1]_ for a list of other supported formats.
      All images besides single channel PNGs are converted using `img_as_uint8`.
      Single Channel PNGs have the following behavior:
      - Integer values in [0, 255] and Boolean types -> img_as_uint8
      - Floating point and other integers -> img_as_uint16
  
      References
      ----------
      .. [1] http://pillow.readthedocs.org/en/latest/handbook/image-file-formats.html
      """
      # default to PNG if file-like object
      if not isinstance(fname, str) and format_str is None:
          format_str = "PNG"
      # Check for png in filename
      if isinstance(fname, str) and fname.lower().endswith(".png"):
          format_str = "PNG"
  
      arr = np.asanyarray(arr)
  
      if arr.dtype.kind == "b":
          arr = arr.astype(np.uint8)
  
      if arr.ndim not in (2, 3):
          raise ValueError(
              f"Invalid shape for image array: {arr.shape}"
          )
  
      if arr.ndim == 3:
          if arr.shape[2] not in (3, 4):
              raise ValueError(
                  "Invalid number of channels in image array."
              )
  
      img = ndarray_to_pil(arr, format_str=format_str)
      img.save(fname, format=format_str, **kwargs)
  
file_path: scikit-image/skimage/io/_plugins/pil_plugin.py
imports: import numpy
  from PIL import Image
  from ...util import img_as_ubyte, img_as_uint
label_desc: Use image node_id 5 for calling a global function with example usage: imsave(fname, arr, format_str) without return types