.. This file is generated by setup.py
Psdtags is a Python library to read and write the Adobe Photoshop(r) specific ImageResources (#34377) and ImageSourceData (#37724) TIFF tags, which contain image resource blocks, layer and mask information found in a typical layered TIFF file created by Photoshop.
The format is specified in the
Adobe Photoshop TIFF Technical Notes (March 22, 2002) <https://www.awaresystems.be/imaging/tiff/specification/TIFFphotoshop.pdf>
and
Adobe Photoshop File Formats Specification (November 2019) <https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/>
.
Adobe Photoshop is a registered trademark of Adobe Systems Inc.
:Author: Christoph Gohlke <https://www.cgohlke.com>
:License: BSD 3-Clause
:Version: 2024.5.24
:DOI: 10.5281/zenodo.7879187 <https://doi.org/10.5281/zenodo.7879187>
Install the psdtags package and all dependencies from the
Python Package Index <https://pypi.org/project/psdtags/>
_::
python -m pip install -U psdtags[all]
View the layer image and metadata stored in a layered TIFF file::
python -m psdtags file.tif
See Examples
_ for using the programming interface.
Source code, examples, and support are available on
GitHub <https://github.com/cgohlke/psdtags>
_.
This revision was tested with the following requirements and dependencies (other versions may work):
CPython <https://www.python.org>
_ 3.9.13, 3.10.11, 3.11.9, 3.12.3NumPy <https://pypi.org/project/numpy/>
_ 1.26.4Imagecodecs <https://pypi.org/project/imagecodecs/>
_ 2024.1.1
(required for compressing/decompressing image data)Tifffile <https://pypi.org/project/tifffile/>
_ 2024.5.22
(required for reading/writing tags from/to TIFF files)Matplotlib <https://pypi.org/project/matplotlib/>
_ 3.8.4
(required for plotting)2024.5.24
2024.2.22
2024.1.15
2024.1.8
2023.8.24
2023.6.15
2023.4.30
2023.2.18
2023.2.8
2022.8.25
2022.2.11
2022.2.2
2022.1.18
2022.1.14
The API is not stable yet and might change between revisions.
This library has been tested with a limited number of files only.
Additional layer information is not yet supported.
Consider psd-tools <https://github.com/psd-tools/psd-tools>
and
pytoshop <https://github.com/mdboom/pytoshop>
for working with
Adobe Photoshop PSD files.
Layered TIFF files can be read or written by Photoshop, Affinity Photo, and Krita.
See also Reading and writing a Photoshop TIFF <https://www.amyspark.me/blog/posts/2021/11/14/reading-and-writing-tiff-psds.html>
_.
Read the ImageSourceData tag value from a layered TIFF file and iterate over all the channels:
.. code-block:: python
>>> isd = TiffImageSourceData.fromtiff('layered.tif')
>>> for layer in isd.layers:
... layer.name
... for channel in layer.channels:
... ch = channel.data # a numpy array
...
'Background'
'Reflect1'
'Reflect2'
'image'
'Layer 1'
'ORight'
'I'
'IShadow'
'O'
Read the ImageResources tag value from the TIFF file, iterate over the blocks, and get the thumbnail image:
.. code-block:: python
>>> res = TiffImageResources.fromtiff('layered.tif')
>>> for block in res.blocks:
... blockname = block.name
...
>>> res.thumbnail().shape
(90, 160, 3)
Write the image, ImageSourceData and ImageResources to a new layered TIFF file:
.. code-block:: python
>>> from tifffile import imread, imwrite
>>> image = imread('layered.tif')
>>> imwrite(
... '_layered.tif',
... image,
... byteorder=isd.byteorder, # must match ImageSourceData
... photometric='rgb', # must match ImageSourceData
... metadata=None, # do not write any tifffile specific metadata
... extratags=[isd.tifftag(maxworkers=4), res.tifftag()],
... )
Verify that the new layered TIFF file contains readable ImageSourceData:
.. code-block:: python
>>> assert isd == TiffImageSourceData.fromtiff('_layered.tif')
>>> assert res == TiffImageResources.fromtiff('_layered.tif')
View the layer and mask information as well as the image resource blocks in a layered TIFF file from a command line::
python -m psdtags layered.tif
Refer to the layered_tiff.py
example in the source distribution for
creating a layered TIFF file from individual layer images.