psdtags


Namepsdtags JSON
Version 2024.5.24 PyPI version JSON
download
home_pagehttps://www.cgohlke.com
SummaryRead and write layered TIFF ImageSourceData and ImageResources tags
upload_time2024-05-23 19:44:43
maintainerNone
docs_urlNone
authorChristoph Gohlke
requires_python>=3.9
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Read and write layered TIFF ImageSourceData and ImageResources tags
===================================================================

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>`_

Quickstart
----------

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>`_.

Requirements
------------

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.3
- `NumPy <https://pypi.org/project/numpy/>`_ 1.26.4
- `Imagecodecs <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)

Revisions
---------

2024.5.24

- Fix GitHub not correctly rendering docstring examples.

2024.2.22

- Fix reading PsdBoolean (#10).
- Fix order of PsdReferencePoint coordinates (breaking).
- Allow reading unaligned PsdLayer blending_ranges.

2024.1.15

- Fix multi-threading.

2024.1.8

- Add option to compress layer channels in multiple threads.
- Improve logging.
- Drop support for Python 3.9 and numpy < 1.23 (NEP29).

2023.8.24

- Fix channel data in layer and pattern blocks must be in big-endian order.

2023.6.15

- Use PsdThumbnailFormat enum for PsdThumbnailBlock.format.

2023.4.30

- Few API changes (breaking).
- Improve object repr.
- Drop support for Python 3.8 and numpy < 1.21 (NEP29).

2023.2.18

- Allow unknown PsdKeys (#5).

2023.2.8

- Change PsdPoint and PsdReferencePoint signatures (breaking).
- Add helper function to create composite from layers.

2022.8.25

- Update metadata.

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 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>`_.

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(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.tif

Refer to the `layered_tiff.py` example in the source distribution for
creating a layered TIFF file from individual layer images.

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.cgohlke.com",
    "name": "psdtags",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Christoph Gohlke",
    "author_email": "cgohlke@cgohlke.com",
    "download_url": "https://files.pythonhosted.org/packages/f2/34/ff61fb4fde832b301b5a9b3d84fe6d4308923c12bfe99bb00d75d891023b/psdtags-2024.5.24.tar.gz",
    "platform": "any",
    "description": "Read and write layered TIFF ImageSourceData and ImageResources tags\r\n===================================================================\r\n\r\nPsdtags is a Python library to read and write the Adobe Photoshop(r) specific\r\nImageResources (#34377) and ImageSourceData (#37724) TIFF tags, which contain\r\nimage resource blocks, layer and mask information found in a typical layered\r\nTIFF file created by Photoshop.\r\n\r\nThe format is specified in the\r\n`Adobe Photoshop TIFF Technical Notes (March 22, 2002)\r\n<https://www.awaresystems.be/imaging/tiff/specification/TIFFphotoshop.pdf>`_\r\nand\r\n`Adobe Photoshop File Formats Specification (November 2019)\r\n<https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/>`_.\r\n\r\nAdobe Photoshop is a registered trademark of Adobe Systems Inc.\r\n\r\n:Author: `Christoph Gohlke <https://www.cgohlke.com>`_\r\n:License: BSD 3-Clause\r\n:Version: 2024.5.24\r\n:DOI: `10.5281/zenodo.7879187 <https://doi.org/10.5281/zenodo.7879187>`_\r\n\r\nQuickstart\r\n----------\r\n\r\nInstall the psdtags package and all dependencies from the\r\n`Python Package Index <https://pypi.org/project/psdtags/>`_::\r\n\r\n    python -m pip install -U psdtags[all]\r\n\r\nView the layer image and metadata stored in a layered TIFF file::\r\n\r\n    python -m psdtags file.tif\r\n\r\nSee `Examples`_ for using the programming interface.\r\n\r\nSource code, examples, and support are available on\r\n`GitHub <https://github.com/cgohlke/psdtags>`_.\r\n\r\nRequirements\r\n------------\r\n\r\nThis revision was tested with the following requirements and dependencies\r\n(other versions may work):\r\n\r\n- `CPython <https://www.python.org>`_ 3.9.13, 3.10.11, 3.11.9, 3.12.3\r\n- `NumPy <https://pypi.org/project/numpy/>`_ 1.26.4\r\n- `Imagecodecs <https://pypi.org/project/imagecodecs/>`_ 2024.1.1\r\n  (required for compressing/decompressing image data)\r\n- `Tifffile <https://pypi.org/project/tifffile/>`_ 2024.5.22\r\n  (required for reading/writing tags from/to TIFF files)\r\n- `Matplotlib <https://pypi.org/project/matplotlib/>`_ 3.8.4\r\n  (required for plotting)\r\n\r\nRevisions\r\n---------\r\n\r\n2024.5.24\r\n\r\n- Fix GitHub not correctly rendering docstring examples.\r\n\r\n2024.2.22\r\n\r\n- Fix reading PsdBoolean (#10).\r\n- Fix order of PsdReferencePoint coordinates (breaking).\r\n- Allow reading unaligned PsdLayer blending_ranges.\r\n\r\n2024.1.15\r\n\r\n- Fix multi-threading.\r\n\r\n2024.1.8\r\n\r\n- Add option to compress layer channels in multiple threads.\r\n- Improve logging.\r\n- Drop support for Python 3.9 and numpy < 1.23 (NEP29).\r\n\r\n2023.8.24\r\n\r\n- Fix channel data in layer and pattern blocks must be in big-endian order.\r\n\r\n2023.6.15\r\n\r\n- Use PsdThumbnailFormat enum for PsdThumbnailBlock.format.\r\n\r\n2023.4.30\r\n\r\n- Few API changes (breaking).\r\n- Improve object repr.\r\n- Drop support for Python 3.8 and numpy < 1.21 (NEP29).\r\n\r\n2023.2.18\r\n\r\n- Allow unknown PsdKeys (#5).\r\n\r\n2023.2.8\r\n\r\n- Change PsdPoint and PsdReferencePoint signatures (breaking).\r\n- Add helper function to create composite from layers.\r\n\r\n2022.8.25\r\n\r\n- Update metadata.\r\n\r\n2022.2.11\r\n\r\n- Fix struct padding.\r\n- Support TiffImageResources.\r\n\r\n2022.2.2\r\n\r\n- Various API changes (breaking).\r\n- Handle additional layer information.\r\n- Preserve structures of unknown format as opaque bytes.\r\n- Add options to skip tag structures of unknown format.\r\n- Add abstract base class for tag structures.\r\n- Add classes for many structures.\r\n\r\n2022.1.18\r\n\r\n- Various API changes (breaking).\r\n- Various fixes for writing TiffImageSourceData.\r\n- Support filter masks.\r\n- Add option to change channel compression on write.\r\n- Warn when skipping ResourceKey sections.\r\n\r\n2022.1.14\r\n\r\n- Initial release.\r\n\r\nNotes\r\n-----\r\n\r\nThe API is not stable yet and might change between revisions.\r\n\r\nThis library has been tested with a limited number of files only.\r\n\r\nAdditional layer information is not yet supported.\r\n\r\nConsider `psd-tools <https://github.com/psd-tools/psd-tools>`_ and\r\n`pytoshop <https://github.com/mdboom/pytoshop>`_  for working with\r\nAdobe Photoshop PSD files.\r\n\r\nLayered TIFF files can be read or written by Photoshop, Affinity Photo, and\r\nKrita.\r\n\r\nSee also `Reading and writing a Photoshop TIFF\r\n<https://www.amyspark.me/blog/posts/2021/11/14/reading-and-writing-tiff-psds.html>`_.\r\n\r\nExamples\r\n--------\r\n\r\nRead the ImageSourceData tag value from a layered TIFF file and iterate over\r\nall the channels:\r\n\r\n>>> isd = TiffImageSourceData.fromtiff('layered.tif')\r\n>>> for layer in isd.layers:\r\n...     layer.name\r\n...     for channel in layer.channels:\r\n...         ch = channel.data  # a numpy array\r\n...\r\n'Background'\r\n'Reflect1'\r\n'Reflect2'\r\n'image'\r\n'Layer 1'\r\n'ORight'\r\n'I'\r\n'IShadow'\r\n'O'\r\n\r\nRead the ImageResources tag value from the TIFF file, iterate over the blocks,\r\nand get the thumbnail image:\r\n\r\n>>> res = TiffImageResources.fromtiff('layered.tif')\r\n>>> for block in res.blocks:\r\n...     blockname = block.name\r\n...\r\n>>> res.thumbnail().shape\r\n(90, 160, 3)\r\n\r\nWrite the image, ImageSourceData and ImageResources to a new layered TIFF file:\r\n\r\n>>> from tifffile import imread, imwrite\r\n>>> image = imread('layered.tif')\r\n>>> imwrite(\r\n...     '_layered.tif',\r\n...     image,\r\n...     byteorder=isd.byteorder,  # must match ImageSourceData\r\n...     photometric='rgb',  # must match ImageSourceData\r\n...     metadata=None,  # do not write any tifffile specific metadata\r\n...     extratags=[isd.tifftag(maxworkers=4), res.tifftag()],\r\n... )\r\n\r\nVerify that the new layered TIFF file contains readable ImageSourceData:\r\n\r\n>>> assert isd == TiffImageSourceData.fromtiff('_layered.tif')\r\n>>> assert res == TiffImageResources.fromtiff('_layered.tif')\r\n\r\nView the layer and mask information as well as the image resource blocks in\r\na layered TIFF file from a command line::\r\n\r\n    python -m psdtags layered.tif\r\n\r\nRefer to the `layered_tiff.py` example in the source distribution for\r\ncreating a layered TIFF file from individual layer images.\r\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Read and write layered TIFF ImageSourceData and ImageResources tags",
    "version": "2024.5.24",
    "project_urls": {
        "Bug Tracker": "https://github.com/cgohlke/psdtags/issues",
        "Homepage": "https://www.cgohlke.com",
        "Source Code": "https://github.com/cgohlke/psdtags"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44eae4c07190e47120191216829c2a4fdb25483531710967d01031a216d4aecf",
                "md5": "20a9786f0a658b50713624f480109764",
                "sha256": "b3afb8ea581d7834474fec3490671bf4105c94deb89679694a63e18bd6d0fb4a"
            },
            "downloads": -1,
            "filename": "psdtags-2024.5.24-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "20a9786f0a658b50713624f480109764",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 30872,
            "upload_time": "2024-05-23T19:44:41",
            "upload_time_iso_8601": "2024-05-23T19:44:41.948800Z",
            "url": "https://files.pythonhosted.org/packages/44/ea/e4c07190e47120191216829c2a4fdb25483531710967d01031a216d4aecf/psdtags-2024.5.24-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f234ff61fb4fde832b301b5a9b3d84fe6d4308923c12bfe99bb00d75d891023b",
                "md5": "e162342ece2ffa4299aa16514699e0f8",
                "sha256": "14481bf4c6e06bde0bb2cade465b2da4245802fe89159029bb369a653ac11609"
            },
            "downloads": -1,
            "filename": "psdtags-2024.5.24.tar.gz",
            "has_sig": false,
            "md5_digest": "e162342ece2ffa4299aa16514699e0f8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 41101,
            "upload_time": "2024-05-23T19:44:43",
            "upload_time_iso_8601": "2024-05-23T19:44:43.800085Z",
            "url": "https://files.pythonhosted.org/packages/f2/34/ff61fb4fde832b301b5a9b3d84fe6d4308923c12bfe99bb00d75d891023b/psdtags-2024.5.24.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-23 19:44:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cgohlke",
    "github_project": "psdtags",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "psdtags"
}
        
Elapsed time: 0.50167s