TIFF-PIL TIFF format (Pillow)

Extensions: .tif, .tiff

From the Pillow docs:

Pillow reads and writes TIFF files. It can read both striped and tiled images, pixel and plane interleaved multi-band images. If you have libtiff and its headers installed, PIL can read and write many kinds of compressed TIFF files. If not, PIL will only read and write uncompressed files.


Beginning in version 5.0.0, Pillow requires libtiff to read or write compressed files. Prior to that release, Pillow had buggy support for reading Packbits, LZW and JPEG compressed TIFFs without using libtiff.

The write() method sets the following info properties:


Compression mode.

New in version Pillow: 2.0.0


Image resolution as an (xdpi, ydpi) tuple, where applicable. You can use the tag attribute to get more detailed information about the image resolution.

New in version Pillow: 1.1.5


Image resolution as an (xres, yres) tuple, where applicable. This is a measurement in whichever unit is specified by the file.

New in version Pillow: 1.1.5

The tag_v2 attribute contains a dictionary of TIFF metadata. The keys are numerical indexes from TAGS_V2. Values are strings or numbers for single items, multiple values are returned in a tuple of values. Rational numbers are returned as a IFDRational object.

New in version Pillow: 3.0.0

For compatibility with legacy code, the tag attribute contains a dictionary of decoded TIFF fields as returned prior to version 3.0.0. Values are returned as either strings or tuples of numeric values. Rational numbers are returned as a tuple of (numerator, denominator).

Deprecated since version 3.0.0.

Saving Tiff Images

The save() method can take the following keyword arguments:


If true, Pillow will save all frames of the image to a multiframe tiff document.

New in version Pillow: 3.4.0


A ImageFileDirectory_v2 object or dict object containing tiff tags and values. The TIFF field type is autodetected for Numeric and string values, any other types require using an ImageFileDirectory_v2 object and setting the type in tagtype with the appropriate numerical value from TiffTags.TYPES.

New in version Pillow: 2.3.0

Metadata values that are of the rational type should be passed in using a IFDRational object.

New in version Pillow: 3.1.0

For compatibility with legacy code, a ImageFileDirectory_v1 object may be passed in this field. However, this is deprecated.

New in version Pillow: 3.0.0


Only some tags are currently supported when writing using libtiff. The supported list is found in LIBTIFF_CORE.

A string containing the desired compression method for the file. (valid only with libtiff installed) Valid compression methods are: None, "tiff_ccitt", "group3", "group4", "tiff_jpeg", "tiff_adobe_deflate", "tiff_thunderscan", "tiff_deflate", "tiff_sgilog", "tiff_sgilog24", "tiff_raw_16"

These arguments to set the tiff header fields are an alternative to using the general tags available through tiffinfo.





A string of “inch”, “centimeter” or “cm”




Either a Float, 2 tuple of (numerator, denominator) or a IFDRational. Resolution implies an equal x and y resolution, dpi also implies a unit of inches.

Parameters for reading

pilmode : str

From the Pillow documentation:

  • ‘L’ (8-bit pixels, grayscale)
  • ‘P’ (8-bit pixels, mapped to any other mode using a color palette)
  • ‘RGB’ (3x8-bit pixels, true color)
  • ‘RGBA’ (4x8-bit pixels, true color with transparency mask)
  • ‘CMYK’ (4x8-bit pixels, color separation)
  • ‘YCbCr’ (3x8-bit pixels, color video format)
  • ‘I’ (32-bit signed integer pixels)
  • ‘F’ (32-bit floating point pixels)

PIL also provides limited support for a few special modes, including ‘LA’ (‘L’ with alpha), ‘RGBX’ (true color with padding) and ‘RGBa’ (true color with premultiplied alpha).

When translating a color image to grayscale (mode ‘L’, ‘I’ or ‘F’), the library uses the ITU-R 601-2 luma transform:

L = R * 299/1000 + G * 587/1000 + B * 114/1000
as_gray : bool
If True, the image is converted using mode ‘F’. When mode is not None and as_gray is True, the image is first converted according to mode, and the result is then “flattened” using mode ‘F’.