:orphan:

.. _TIFF-PIL:

TIFF-PIL TIFF format (Pillow)
=============================

Extensions: ``.tif``, ``.tiff``

*This is a copy from the Pillow docs.*


PIL reads and writes TIFF files. It can read both striped and tiled images,
pixel and plane interleaved multi-band images, and either uncompressed, or
Packbits, LZW, or JPEG compressed images.

If you have libtiff and its headers installed, PIL can read and write many more
kinds of compressed TIFF files. If not, PIL will always write uncompressed
files.

The :py:meth:`~PIL.Image.Image.write` method sets the following
:py:attr:`~PIL.Image.Image.info` properties:

**compression**
    Compression mode.

    .. versionadded:: Pillow  2.0.0

**dpi**
    Image resolution as an ``(xdpi, ydpi)`` tuple, where applicable. You can use
    the :py:attr:`~PIL.Image.Image.tag` attribute to get more detailed
    information about the image resolution.

    .. versionadded:: Pillow  1.1.5

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

    .. versionadded:: Pillow  1.1.5


The :py:attr:`~PIL.Image.Image.tag_v2` attribute contains a dictionary
of TIFF metadata. The keys are numerical indexes from
:py:attr:`~PIL.TiffTags.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 :py:class:`~PIL.TiffImagePlugin.IFDRational`
object.

    .. versionadded:: Pillow  3.0.0

For compatibility with legacy code, the
:py:attr:`~PIL.Image.Image.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:: 3.0.0


Saving Tiff Images
~~~~~~~~~~~~~~~~~~

The :py:meth:`~PIL.Image.Image.save` method can take the following keyword arguments:

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

    .. versionadded:: Pillow  3.4.0

**tiffinfo**
    A :py:class:`~PIL.TiffImagePlugin.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 :py:class:`~PIL.TiffImagePlugin.ImageFileDirectory_v2`
    object and setting the type in
    :py:attr:`~PIL.TiffImagePlugin.ImageFileDirectory_v2.tagtype` with
    the appropriate numerical value from
    ``TiffTags.TYPES``.

    .. versionadded:: Pillow  2.3.0

    Metadata values that are of the rational type should be passed in
    using a :py:class:`~PIL.TiffImagePlugin.IFDRational` object.

    .. versionadded:: Pillow  3.1.0

    For compatibility with legacy code, a
    :py:class:`~PIL.TiffImagePlugin.ImageFileDirectory_v1` object may
    be passed in this field. However, this is deprecated.

    .. versionadded:: Pillow  3.0.0

 .. note::

    Only some tags are currently supported when writing using
    libtiff. The supported list is found in
    :py:attr:`~PIL:TiffTags.LIBTIFF_CORE`.

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

**description**

**software**

**date_time**

**artist**

**copyright**
    Strings

**resolution_unit**
    A string of "inch", "centimeter" or "cm"

**resolution**

**x_resolution**

**y_resolution**

**dpi**
    Either a Float, 2 tuple of (numerator, denominator) or a
    :py:class:`~PIL.TiffImagePlugin.IFDRational`. Resolution implies
    an equal x and y resolution, dpi also implies a unit of inches.



