:orphan:

.. _TIFF-PIL:

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.

.. note::

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


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

