Skip to main content

Read and write layered TIFF ImageSourceData and ImageResources tags

Project description

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) and Adobe Photoshop File Formats Specification (November 2019).

Adobe Photoshop is a registered trademark of Adobe Systems Inc.

Author:

Christoph Gohlke

Organization:

Laboratory for Fluorescence Dynamics, University of California, Irvine

License:

BSD 3-Clause

Version:

2022.2.11

Status:

Alpha

Requirements

This release has been tested with the following requirements and dependencies (other versions may work):

Revisions

2022.2.11

Fix struct padding. Support TiffImageResources.

2022.2.2

Various 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.18

Various 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.14

Initial release.

Notes

The API is not stable yet and might change between revisions.

This module has been tested with a limited number of files only.

Additional layer information is not yet supported.

Consider psd-tools and pytoshop for working with Adobe Photoshop PSD files.

Examples

Read 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(), res.tifftag()],
... )

Verify that the new layered TIFF file contains readable ImageSourceData:

>>> assert isd == TiffImageSourceData.fromtiff('_layered.tif')
>>> assert res == TiffImageResources.fromtiff('_layered.tif')

To view the layer and mask information as well as the image resource blocks in a layered TIFF file from a command line, run:

python -m psdtags layered.tif

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psdtags-2022.2.11.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psdtags-2022.2.11-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file psdtags-2022.2.11.tar.gz.

File metadata

  • Download URL: psdtags-2022.2.11.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for psdtags-2022.2.11.tar.gz
Algorithm Hash digest
SHA256 44a46a80de372992810c509052c48ecdcb6167578163063b25179e008b99929d
MD5 705a39cf1bdf18a9ea3dc5db9eb31576
BLAKE2b-256 80ae4dc20c050e5868e35677904694bfa2a960a9e7f1d919bcef0f0121622541

See more details on using hashes here.

File details

Details for the file psdtags-2022.2.11-py3-none-any.whl.

File metadata

  • Download URL: psdtags-2022.2.11-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for psdtags-2022.2.11-py3-none-any.whl
Algorithm Hash digest
SHA256 4f33928c960dfbe15c8147e720aca244e437f95821a42f35ee05446db56fcdc6
MD5 b55903da540552a32116a3926f818d40
BLAKE2b-256 df60bd2ad3e43ea28ce3b24bc6e79dde501bd9a0b6e2dd9d2296e12561a80113

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page