docstr: Write an ndimage to the URI specified in path.
  
  If the URI points to a file on the current host and the file does not
  yet exist it will be created. If the file exists already, it will be
  appended if possible; otherwise, it will be replaced.
  
  If necessary, the image is broken down along the leading dimension to
  fit into individual frames of the chosen format. If the format doesn't
  support multiple frames, and IOError is raised.
  
  Parameters
  ----------
  image : ndarray or list
      The ndimage to write. If a list is given each element is expected to
      be an ndimage.
  mode : str
      Specify the image's color format. If None (default), the mode is
      inferred from the array's shape and dtype. Possible modes can be
      found at:
      https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes
  format : str
      Optional format override. If omitted, the format to use is
      determined from the filename extension. If a file object was used
      instead of a filename, this parameter must always be used.
  is_batch : bool
      Explicitly tell the writer that ``image`` is a batch of images
      (True) or not (False). If None, the writer will guess this from the
      provided ``mode`` or ``image.shape``. While the latter often works,
      it may cause problems for small images due to aliasing of spatial
      and color-channel axes.
  kwargs : ...
      Extra arguments to pass to pillow. If a writer doesn't recognise an
      option, it is silently ignored. The available options are described
      in pillow's `image format documentation
      <https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html>`_
      for each writer.
  
  Notes
  -----
  When writing batches of very narrow (2-4 pixels wide) gray images set
  the ``mode`` explicitly to avoid the batch being identified as a colored
  image.
docstr_tok: ["Write","an","ndimage","to","the","URI","specified","in","path",".","If","the","URI","points","to","a","file","on","the","current","host","and","the","file","does","not","yet","exist","it","will","be","created",".","If","the","file","exists","already",",","it","will","be","appended","if","possible",";","otherwise",",","it","will","be","replaced",".","If","necessary",",","the","image","is","broken","down","along","the","leading","dimension","to","fit","into","individual","frames","of","the","chosen","format",".","If","the","format","doesn't","support","multiple","frames",",","and","IOError","is","raised",".","Parameters","--","--","--","--","--","image",":","ndarray","or","list","The","ndimage","to","write",".","If","a","list","is","given","each","element","is","expected","to","be","an","ndimage",".","mode",":","str","Specify","the","image","'s","color","format",".","If","None","(","default",")",",","the","mode","is","inferred","from","the","array","'s","shape","and","dtype",".","Possible","modes","can","be","found","at",":","https",":","\/\/pillow.readthedocs.io\/en\/stable\/handbook\/concepts.html","#","modes","format",":","str","Optional","format","override",".","If","omitted",",","the","format","to","use","is","determined","from","the","filename","extension",".","If","a","file","object","was","used","instead","of","a","filename",",","this","parameter","must","always","be","used",".","is_batch",":","bool","Explicitly","tell","the","writer","that","``","image","``","is","a","batch","of","images","(","True",")","or","not","(","False",")",".","If","None",",","the","writer","will","guess","this","from","the","provided","``","mode","``","or","``","image.shape","``",".","While","the","latter","often","works",",","it","may","cause","problems","for","small","images","due","to","aliasing","of","spatial","and","color-channel","axes",".","kwargs",":","...","Extra","arguments","to","pass","to","pillow",".","If","a","writer","does","n't","recognise","an","option",",","it","is","silently","ignored",".","The","available","options","are","described","in","pillow","'s","`","image","format","documentation","<","https",":","\/\/pillow.readthedocs.io\/en\/stable\/handbook\/image-file-formats.html",">","`","_","for","each","writer",".","Notes","--","--","-","When","writing","batches","of","very","narrow","(","2-4","pixels","wide",")","gray","images","set","the","``","mode","``","explicitly","to","avoid","the","batch","being","identified","as","a","colored","image","."]
code: def write(
      self,
      ndimage: Union[ArrayLike, List[ArrayLike]],
      *,
      mode: str = None,
      format: str = None,
      is_batch: bool = None,
      **kwargs,
  ) -> Optional[bytes]:
      """
      Write an ndimage to the URI specified in path.
  
      If the URI points to a file on the current host and the file does not
      yet exist it will be created. If the file exists already, it will be
      appended if possible; otherwise, it will be replaced.
  
      If necessary, the image is broken down along the leading dimension to
      fit into individual frames of the chosen format. If the format doesn't
      support multiple frames, and IOError is raised.
  
      Parameters
      ----------
      image : ndarray or list
          The ndimage to write. If a list is given each element is expected to
          be an ndimage.
      mode : str
          Specify the image's color format. If None (default), the mode is
          inferred from the array's shape and dtype. Possible modes can be
          found at:
          https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes
      format : str
          Optional format override. If omitted, the format to use is
          determined from the filename extension. If a file object was used
          instead of a filename, this parameter must always be used.
      is_batch : bool
          Explicitly tell the writer that ``image`` is a batch of images
          (True) or not (False). If None, the writer will guess this from the
          provided ``mode`` or ``image.shape``. While the latter often works,
          it may cause problems for small images due to aliasing of spatial
          and color-channel axes.
      kwargs : ...
          Extra arguments to pass to pillow. If a writer doesn't recognise an
          option, it is silently ignored. The available options are described
          in pillow's `image format documentation
          <https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html>`_
          for each writer.
  
      Notes
      -----
      When writing batches of very narrow (2-4 pixels wide) gray images set
      the ``mode`` explicitly to avoid the batch being identified as a colored
      image.
  
      """
      if "fps" in kwargs:
          warnings.warn(
              "The keyword `fps` is no longer supported. Use `duration`"
              "(in ms) instead, e.g. `fps=50` == `duration=20` (1000 * 1/50).",
              DeprecationWarning,
          )
          kwargs["duration"] = 1000 * 1 / kwargs.get("fps")
  
      if isinstance(ndimage, list):
          ndimage = np.stack(ndimage, axis=0)
          is_batch = True
      else:
          ndimage = np.asarray(ndimage)
  
      # check if ndimage is a batch of frames/pages (e.g. for writing GIF)
      # if mode is given, use it; otherwise fall back to image.ndim only
      if is_batch is not None:
          pass
      elif mode is not None:
          is_batch = (
              ndimage.ndim > 3
              if Image.getmodebands(mode) > 1
              else ndimage.ndim > 2
          )
      elif ndimage.ndim == 2:
          is_batch = False
      elif ndimage.ndim == 3 and ndimage.shape[-1] == 1:
          raise ValueError("Can't write images with one color channel.")
      elif ndimage.ndim == 3 and ndimage.shape[-1] in [2, 3, 4]:
          # Note: this makes a channel-last assumption
          is_batch = False
      else:
          is_batch = True
  
      if not is_batch:
          ndimage = ndimage[None, ...]
  
      for frame in ndimage:
          pil_frame = Image.fromarray(frame, mode=mode)
          if "bits" in kwargs:
              pil_frame = pil_frame.quantize(colors=2 ** kwargs["bits"])
          self.images_to_write.append(pil_frame)
  
      if (
          format is not None
          and "format" in self.save_args
          and self.save_args["format"] != format
      ):
          old_format = self.save_args["format"]
          warnings.warn(
              "Changing the output format during incremental"
              " writes is strongly discouraged."
              f" Was `{old_format}`, is now `{format}`.",
              UserWarning,
          )
  
      extension = self.request.extension or self.request.format_hint
      self.save_args["format"] = (
          format or Image.registered_extensions()[extension]
      )
      self.save_args.update(kwargs)
  
      # when writing to `bytes` we flush instantly
      result = None
      if self._request._uri_type == URI_BYTES:
          self._flush_writer()
          file = cast(BytesIO, self._request.get_file())
          result = file.getvalue()
  
      return result
  
imports: import sys
  import warnings
  from io import BytesIO
  from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union, cast
  import numpy
  from PIL import ExifTags, GifImagePlugin, Image, ImageSequence, UnidentifiedImageError
  from PIL import __version__
  from ..core.request import URI_BYTES, InitializationError, IOMode, Request
  from ..core.v3_plugin_api import ImageProperties, PluginV3
  from ..typing import ArrayLike
label_desc: Use image node_id 6 for calling the PillowPlugin obj's underlying member method code with example usage: obj.write(ndimage) and returns: result