Package: psd-tools3
psd-tools3is a package for reading Adobe Photoshop PSD files
as described inspecificationto Python data structures.This is a fork ofpsd-toolsthat adds a couple of enhancements to the
original version.Installationpipinstallpsd-tools3Pillowshould be installed if you want work with PSD image and layer data:
export images to PNG, process them.PILlibrary should also work.pipinstallPillowNoteIn order to extract images from 32bit PSD files PIL/Pillow must be built
with LITTLECMS or LITTLECMS2 support.psd-tools3 also has a rudimentary support forPymaging.Pymaging installation instructionsare available in pymaging docs.Command lineThe current tool supports PNG/JPEG export:psd-toolsconvert<psd_filename><out_filename>[options]psd-toolsexport_layer<psd_filename><layer_index><out_filename>[options]psd-toolsdebug<filename>[options]psd-tools-h|--helppsd-tools--versionAPI UsageLoad an image:>>> from psd_tools import PSDImage
>>> psd = PSDImage.load('my_image.psd')Print the layer structure:>>> psd.print_tree()Read image header:>>> psd.header
PsdHeader(number_of_channels=3, height=200, width=100, depth=8, color_mode=RGB)Access its layers:>>> psd.layers
[<group: 'Group 2', layer_count=1, mask=None, visible=1>,
 <group: 'Group 1', layer_count=1, mask=None, visible=1>,
 <pixel: 'Background', size=100x200, x=0, y=0, mask=None, visible=1>]

>>> list(psd.descendants())
[<group: 'Group 2', layer_count=1, mask=None, visible=1>,
 <shape: 'Shape 2', size=43x62, x=40, y=72, mask=None, visible=1)>,
 <group: 'Group 1', layer_count=1, mask=None, visible=1>,
 ...
 ]Work with a layer group:>>> group2 = psd.layers[0]
>>> group2.name
Group 2

>>> group2.visible
True

>>> group2.opacity
255

>>> group2.blend_mode == 'normal'
True

>>> group2.layers
[<shape: 'Shape 2', size=43x62, x=40, y=72, mask=None, visible=1)>]Work with a layer:>>> layer = group2.layers[0]
>>> layer.name
Shape 2

>>> layer.kind
type

>>> layer.bbox
BBox(x1=40, y1=72, x2=83, y2=134)

>>> layer.bbox.width, layer.bbox.height
(43, 62)

>>> layer.visible, layer.opacity, layer.blend_mode
(True, 255, 'normal')

>>> layer.text
'Text inside a text box'

>>> layer.as_PIL()
<PIL.Image.Image image mode=RGBA size=43x62 at ...>

>>> mask = layer.mask
>>> mask.bbox
BBox(x1=40, y1=72, x2=83, y2=134)

>>> mask.as_PIL()
<PIL.Image.Image image mode=L size=43x62 at ...>

>>> layer.clip_layers
[<shape: 'Clipped', size=43x62, x=40, y=72, mask=None, visible=1)>, ...]

>>> layer.effects
[<GradientOverlay>]Export a single layer:>>> layer_image = layer.as_PIL()
>>> layer_image.save('layer.png')Export the merged image:>>> merged_image = psd.as_PIL()
>>> merged_image.save('my_image.png')The same usingPymaging:>>> merged_image = psd.as_pymaging()
>>> merged_image.save_to_path('my_image.png')
>>> layer_image = layer.as_pymaging()
>>> layer_image.save_to_path('layer.png')Export a thumbnail in PIL Image:>>> thumbnail_image = psd.thumbnail()Export layer group (experimental):>>> group_image = group2.as_PIL()
>>> group_image.save('group.png')Design overviewThe process of handling a PSD file is split into 3 stages:“Reading”: the file is read and parsed to low-level data
structures that closely match the specification. No user-accessible
images are constructed; image resources blocks and additional layer
information are extracted but not parsed (they remain just keys
with a binary data). The goal is to extract all information
from a PSD file.“Decoding”: image resource blocks and additional layer
information blocks are parsed to a more detailed data structures
(that are still based on a specification). There are a lot of PSD
data types and the library currently doesn’t handle them all, but
it should be easy to add the parsing code for the missing PSD data
structures if needed.After (1) and (2) we have an in-memory data structure that closely
resembles PSD file; it should be fairly complete but very low-level
and not easy to use. So there is a third stage:“User-facing API”: PSD image is converted to an user-friendly object
that supports layer groups, exporting data asPIL.Imageorpymaging.Image, etc.Stage separation also means user-facing API may be opinionated:
if somebody doesn’t like it then it should possible to build an
another API based on lower-level decoded PSD file.psd-tools3tries not to throw away information from the original
PSD file; even if the library can’t parse some info, this info
will be likely available somewhere as raw bytes (open a bug if this is
not the case). This should make it possible to modify and write PSD
files (currently not implemented; contributions are welcome).FeaturesSupported:reading of RGB, RGBA, CMYK, CMYKA and Grayscale images;8bit, 16bit and 32bit channels;all PSD compression methods are supported (not only the most
common RAW and RLE);image ICC profile is taken into account;many image resource types and tagged block types are decoded;layer effects information is decoded;Descriptor structures are decoded;there is an optional Cython extension to make the parsing fast;very basic & experimental layer merging;support both PSD and PSB file formats;EngineData structure is decoded;EXIF data is taken into account.Not implemented:reading of Duotone, LAB, etc. images;some image resource types and tagged blocks are not decoded
(they are attached to the result as raw bytes);some of the raw Descriptor values are not decoded;this library can’t reliably blend layers together: it is possible to export
a single layer and to export a final image, but rendering of
e.g. layer group may produce incorrect results;the writing of PSD images is not implemented;Pymagingsupport is limited: it only supports 8bit RGB/RGBA
images, ICC profiles are not applied, layer merging doesn’t work, etc.If you need some of unimplemented features then please file an issue
or implement it yourself (pull requests are welcome in this case).ContributingDevelopment happens at github:source code,bug tracker.
Feel free to submit ideas, bugs or pull requests.In case of bugs it would be helpful to provide a small PSD file
demonstrating the issue; this file may be added to a test suite.In order to run tests, make sure PIL/Pillow is built with LittleCMS
or LittleCMS2 support, installtoxand type:toxInstall Sphinx to generate documents:pipinstallsphinxsphinx_rtd_themeOnce installed, useMakefile:make-Cdocshtmlfrom the source checkout.The license is MIT.AcknowledgmentsGreat thanks to the originalpsd-toolsauthor Mikhail Korobov.
A full list of contributors can be found here:https://github.com/kyamagu/psd-tools3/blob/master/AUTHORS.txtVersion 1.9.1, 2021-09-08add pip install timeout to prevent Travis CI jobs from hangingbump pillow from 8.2.0 to 8.3.2 (dependabot security vulnerability)1.9.0 (2021-06-16)upgrade Py dependencymerge changes from kyamagu/psd-toolsadd Scrutinizer & Style CI supportoptimize dependencies1.8.8 (2019-02-20)revert package name topsd_tools;prepare merging to the main repo.1.8.7 (2019-02-15)minor bugfix.1.8.6 (2019-02-14)change _psd pointer in PSDImage;add version property;support fill effects in composer.1.8.5 (2019-02-05)change tagged block/image resource singleton accessor in user API;add documentation on iterator order;fix export setting 1 big key config;fix computer info big key config.1.8.3 (2019-02-01)add channel size checking in topil;add mlst metadata decoding;fix key collision issue in descriptor;performance improvement for packbit encoding/decoding;drop cython dependency in travis config;implement thumbnail, is_group, and parent methods in PSDImage.1.8.0 (2019-01-24)major API changes;package name changed topsd_tools2;completely rewritten decoding subpackagepsd_tools2.psd;improved composer functionality;file write support;drop cython compression module and makes the package pure-python;drop pymaging support.1.7.30 (2019-01-15)composer alpha blending fix;documentation fix.1.7.28 (2019-01-09)support cinf tagged block.1.7.27 (2018-12-06)add missing extra image resource block signatures.1.7.26 (2018-12-03)move psd_tools tests under tests/psd_tools.1.7.25 (2018-11-27)fix alpha channel visibility of composed image.1.7.24 (2018-11-21)fix unit rectangle drawing size.1.7.23 (2018-11-20)fix ignored visibility in bbox calculation.1.7.22 (2018-10-12)drop py34 support;fix tobytes deprecation warning.1.7.21 (2018-10-10)fix gradient descriptor bug.1.7.20 (2018-10-09)fix coloroverlay bug;fix gradient angle bug;fix curves decoder bug.1.7.19 (2018-10-02)fix descriptor decoder.1.7.18 (2018-09-26)add shape rendering incompose();add grayscale support.1.7.17 (2018-09-21)fixhas_pixel()condition.1.7.16 (2018-08-29)fix fill opacity incompose();workaround for brokenPrintFlags.1.7.15 (2018-08-28)fix color overlay issue incompose().1.7.14 (2018-08-24)fixverbosearg for python 3.7 compatibility.1.7.13 (2018-08-10)fixhas_pixel()for partial channels;support color overlay incompose().1.7.12 (2018-06-25)fix mask rendering in compose (Thanks @andrey-hider and @nkato).1.7.11 (2018-06-11)unicode bugfixes.1.7.10 (2018-06-06)fix descriptor decoding errors;minor bugfixes.1.7.9 (2018-06-05)fix UnicodeError in exif;workaround for irregular descriptor name;add undocumentedextntagged block decoding;move duplicated icc module to subpackage;support PIL rendering with extra alpha channels.1.7.8 (2018-05-29)update documentation;fix PEP8 compliance;rename merge_layers to compose.1.7.7 (2018-05-02)fix white background issue inas_PIL().1.7.6 (2018-04-27)add quality testing;fix disabled mask.1.7.5 (2018-04-25)fixhas_mask()condition;add mask composition inmerge_layers();fix mask display.1.7.4 (2018-03-06)fix infinity loop inprint_tree().1.7.3 (2018-02-27)add vector origination API;fix shape and vector mask identification;change enum name conversion;update docs.1.7.2 (2018-02-14)add adjustments API;add mask API;bugfix for tagged_blocks decoders.1.7.1 (2018-02-08)add mask user API;add layer coordinate user API;add vector mask and vector stroke API;cleanup user API;add automatic descriptor conversion.1.7.0 (2018-01-25)cleanup user API organization;remove json encoder api;make cli a package main.1.6.7 (2018-01-17)workaround for anaconda 2.7 pillow;bbox existence checkf.1.6.6 (2018-01-10)experimental clipping support inmerge_layer();revertas_PIL()inAdjustmentLayer.1.6.5 (2017-12-22)Small fix for erroneous unicode path name1.6.4 (2017-12-20)Addall_layers()method;Add_image_resource_blocksproperty;Addthumbnail()method.1.6.3 (2017-09-27)documentation updates;github repository renamed to psd-tools2;AdjustmentLayer fix.1.6.2 (2017-09-13)layer class structure reorganization;add Effects API;add TypeLayer API methods.1.6 (2017-09-08)PSDImage user API update;user API adds distinct layer types;Sphinx documentation.1.5 (2017-07-13)implemented many decodings of image resources and tagged blocks;implemented EngineData text information;user API for getting mask and patterns;user API to calculate bbox for shape layers;1.4 (2017-01-02)Fixed reading of layer mask data (thanks Evgeny Kopylov);Python 2.6 support is dropped;Python 3.6 support is added (thanks Leendert Brouwer);extension is rebuilt with Cython 0.25.2.1.3 (2016-01-25)fixed references decoding (thanks Josh Drake);fixed PIL support for CMYK files (thanks Michael Wu);optional C extension is rebuilt with Cython 0.23.4;Python 3.2 support is dropped; the package still works in Python 3.2,
but the compatibility is no longer checked by tests, and so it can break
in future.declare Python 3.5 as supported.1.2 (2015-01-27)implemented extraction of embedded files (embedded smart objects) -
thanks Volker Braun;optional C extension is rebuilt with Cython 0.21.2.hg mirror on bitbucket is dropped, sorry!1.1 (2014-11-17)improved METADATA_SETTING decoding (thanks Evgeny Kopylov);layer comps decoding (thanks Evgeny Kopylov);improved smart objects decoding (thanks Joey Gentry);user API for getting layer transforms and placed layer size
(thanks Joey Gentry);IPython import is deferred to speeduppsd-tools.pycommand-line utility;_RootGroup.__repr__is fixed;warning message building is more robust;optional C extension is rebuilt with Cython 0.21.1.1.0 (2014-07-24)Fixed reading of images with layer masks (thanks Evgeny Kopylov);improved mask data decoding (thanks Evgeny Kopylov);fixed syncronization in case of8B64signatures (thanks Evgeny Kopylov);fixed reading of layers with zero length (thanks Evgeny Kopylov);fixed Descriptor parsing (thanks Evgeny Kopylov);some of the descriptor structures and tagged block constants are renamed (thanks Evgeny Kopylov);PATH_SELECTION_STATE decoding (thanks Evgeny Kopylov);the library is switched to setuptools; docopt is now installed automatically.0.10 (2014-06-15)Layer effects parsing (thanks Evgeny Kopylov);trailing null bytes are stripped from descriptor strings
(thanks Evgeny Kopylov);“Reference” and “List” descriptor parsing is fixed
(thanks Evgeny Kopylov);scalar descriptor values (doubles, floats, booleans) are now returned
as scalars, not as lists of size 1 (thanks Evgeny Kopylov);fixed reading of EngineData past declared length
(thanks Carlton P. Taylor);“background color” Image Resource parsing (thanks Evgeny Kopylov);psd_tools.decoder.actions.Enum.enumfield is renamed topsd_tools.decoder.actions.Enum.value(thanks Evgeny Kopylov);code simplification - constants are now bytestrings as they should be
(thanks Evgeny Kopylov);Python 3.4 is supported.0.9.1 (2014-03-26)Improved merging of transparent layers (thanks Vladimir Timofeev);fixed layer merging and bounding box calculations for empty layers
(thanks Vladimir Timofeev);C extension is rebuilt with Cython 0.20.1.0.9 (2013-12-03)psd-tools.pycommand-line interface is changed, ‘debug’ command is added;pretty-printing of internal structures;pymaging support is fixed;allow ‘MeSa’ to be a signature for image resource blocks
(thanks Alexey Buzanov);psd_tools.debug.debug_viewutility function is fixed;Photoshop CC constants are added;Photoshop CC vector origination data is decoded;binary data is preserved if descriptor parsing fails;more verbose logging for PSD reader;channel data reader became more robust - now it doesn’t read past
declared channel length;psd-tools.py –versioncommand is fixed;lsdktagged blocks parsing: this fixes some issues with layer grouping
(thanks Ivan Maradzhyiski for the bug report and the patch);CMYK images support is added (thanks Alexey Buzanov, Guillermo Rauch andhttps://github.com/a-e-mfor the help);Grayscale images support is added (thankshttps://github.com/a-e-m);LittleCMS is now optional (but it is still required to get proper colors).0.8.4 (2013-06-12)Point and Millimeter types are added to UnitFloatType (thanks Doug Ellwanger).0.8.3 (2013-06-01)Some issues with descriptor parsing are fixed (thanks Luke Petre).0.8.2 (2013-04-12)Python 2.x: reading data from file-like objects is fixed
(thanks Pavel Zinovkin).0.8.1 (2013-03-02)Fixed parsing of layer groups without explicit OPEN_FOLDER mark;Cython extension is rebuilt with Cython 0.18.0.8 (2013-02-26)Descriptor parsing (thanks Oliver Zheng);text (as string) is extracted from text layers (thanks Oliver Zheng);improved support for optional building of Cython extension.0.7.1 (2012-12-27)Typo is fixed:LayerRecord.cilppingshould beLayerRecord.clipping.
Thanks Oliver Zheng.0.7 (2012-11-08)Highly experimental: basic layer merging is implemented
(e.g. it is now possible to export layer group to a PIL image);Layer.visibleno longer takes group visibility in account;Layer.visible_globalis the oldLayer.visible;psd_tools.user_api.combined_bboxmade public;Layer.widthandLayer.heightare removed (uselayer.bbox.widthandlayer.bbox.heightinstead);pil_support.composite_image_to_PILis renamed topil_support.extract_composite_imageandpil_support.layer_to_PILis renamed topil_support.extract_layer_imagein order to have the same API forpil_supportandpymaging_support.0.6 (2012-11-06)psd.composite_image()is renamed topsd.as_PIL();Pymaging support:psd.as_pymaging()andlayer.as_pymaging()methods.0.5 (2012-11-05)Support for zip and zip-with-prediction compression methods is added;support for 16/32bit layers is added;optional Cython extension for faster zip-with-prediction decompression;other speed improvements.0.2 (2012-11-04)Initial support for 16bit and 32bit PSD files:psd-toolsv0.2 can
read composite (merged) images for such files and extract information
(names, dimensions, hierarchy, etc.) about layers and groups of 16/32bit PSD;
extracting image data for distinct layers in 16/32bit PSD files is not
suported yet;betterLayer.__repr__;bboxproperty forGroup.0.1.4 (2012-11-01)Packaging is fixed in this release.0.1.3 (2012-11-01)Better support for 32bit images (still incomplete);reader is able to handle “global” tagged layer info blocks that
was previously discarded.0.1.2 (2012-10-30)warn about 32bit images;transparency support for composite images.0.1.1 (2012-10-29)Initial release (v0.1 had packaging issues).