Skip to main content
`Ctrl`+`K`

# imageio.plugins.pillow.PillowPlugin.write

PillowPlugin.write(ndimage: ArrayLike | List[ArrayLike], *, mode: str = None, format: str = None, is_batch: bool = None, **kwargs) → bytes | None

  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 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.