Summary

https://pillow.readthedocs.io/en/stable/reference/Image.html

PIL.Image.open(fp, mode=‘r’, formats=None)

  • fp – A filename (string), pathlib.Path object or a file object.

classPIL.Image.Image[source]

This class represents an image object. To create Image objects, use the appropriate factory functions. There’s hardly ever any reason to call the Image constructor directly.

  • open()
  • new()
  • frombytes()

An instance of the Image class has the following methods. Unless otherwise stated, all methods return a new instance of the Image class, holding the resulting image.

Image.save(fp, format=None, **params)[source]

Saves this image under the given filename. If no format is specified, the format to use is determined from the filename extension, if possible. Keyword options can be used to provide additional instructions to the writer. If a writer doesn’t recognise an option, it is silently ignored. The available options are described in the image format documentation for each writer. You can use a file object instead of a filename. In this case, you must always specify the format. The file object must implement the seek, tell, and write methods, and be opened in binary mode.

Parameters

  • fp – A filename (string), pathlib.Path object or file object.
  • format – 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 should always be used.
  • params – Extra parameters to the image writer.

Returns

None

Raises

ValueError – If the output format could not be determined from the file name. Use the format option to solve this.

OSError – If the file could not be written. The file may have been created, and may contain partial data.