Package: psdtags
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 theAdobe Photoshop TIFF Technical Notes (March 22, 2002)andAdobe Photoshop File Formats Specification (November 2019).Adobe Photoshop is a registered trademark of Adobe Systems Inc.Author:Christoph GohlkeLicense:BSD 3-ClauseVersion:2024.2.22DOI:10.5281/zenodo.7879187QuickstartInstall the psdtags package and all dependencies from thePython Package Index:python -m pip install -U psdtags[all]View the layer image and metadata stored in a layered TIFF file:python -m psdtags file.tifSeeExamplesfor using the programming interface.Source code, examples, and support are available onGitHub.RequirementsThis revision was tested with the following requirements and dependencies
(other versions may work):CPython3.9.13, 3.10.11, 3.11.8, 3.12.2NumPy1.26.4Imagecodecs2024.1.1
(required for compressing/decompressing image data)Tifffile2024.2.12
(required for reading/writing tags from/to TIFF files)Matplotlib3.8.3
(required for plotting)Revisions2024.2.22Fix reading PsdBoolean (#10).Fix order of PsdReferencePoint coordinates (breaking).Allow reading unaligned PsdLayer blending_ranges.2024.1.15Fix multi-threading.2024.1.8Add option to compress layer channels in multiple threads.Improve logging.Drop support for Python 3.9 and numpy < 1.23 (NEP29).2023.8.24Fix channel data in layer and pattern blocks must be in big-endian order.2023.6.15Use PsdThumbnailFormat enum for PsdThumbnailBlock.format.2023.4.30Few API changes (breaking).Improve object repr.Drop support for Python 3.8 and numpy < 1.21 (NEP29).2023.2.18Allow unknown PsdKeys (#5).2023.2.8Change PsdPoint and PsdReferencePoint signatures (breaking).Add helper function to create composite from layers.2022.8.25Update metadata.2022.2.11Fix struct padding.Support TiffImageResources.2022.2.2Various API changes (breaking).Handle additional layer information.Preserve structures of unknown format as opaque bytes.Add options to skip tag structures of unknown format.Add abstract base class for tag structures.Add classes for many structures.2022.1.18Various API changes (breaking).Various fixes for writing TiffImageSourceData.Support filter masks.Add option to change channel compression on write.Warn when skipping ResourceKey sections.2022.1.14Initial release.NotesThe 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.Considerpsd-toolsandpytoshopfor working with
Adobe Photoshop PSD files.Layered TIFF files can be read or written by Photoshop, Affinity Photo, and
Krita.See alsoReading and writing a Photoshop TIFF.ExamplesRead the ImageSourceData tag value from a layered TIFF file and iterate over
all the channels:>>> 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:>>> 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:>>> 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:>>> 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.tifRefer to thelayered_tiff.pyexample in the source distribution for
creating a layered TIFF file from individual layer images.