Python package for working with Adobe Photoshop PSD files
Project description
psd-tools is a package for reading Adobe Photoshop PSD files (as described in specification) to Python data structures.
Installation
pip install psd-tools
There are also optional dependencies: docopt for command-line interface and PIL (or Pillow) for accessing PSD layer data as PIL images:
pip install Pillow pip install docopt
Usage
Load an image:
>>> from psd_tools import PSDImage >>> psd = PSDImage.load('my_image.psd')
Access its layers:
>>> psd.layers [<psd_tools.Group: 'Group 2', layer_count=1>, <psd_tools.Group: 'Group 1', layer_count=1>, <psd_tools.Layer: 'Background', size=100x200>]
Work with a layer group:
>>> group2 = psd.layers[0] >>> group2.name Group 2 >>> group2.visible True >>> group2.closed False >>> group2.opacity 255 >>> from psd_tools.constants import BlendMode >>> group2.blend_mode == BlendMode.NORMAL True >>> group2.layers [<psd_tools.Layer: 'Shape 2', size=43x62>]
Work with a layer:
>>> layer = group2.layers[0] >>> layer.name Shape 2 >>> layer.bbox (40, 72, 83, 134) >>> layer.width, layer.height (43, 62) >>> layer.visible, layer.opacity, layer.blend_mode (True, 255, u'norm') >>> layer.as_PIL() <PIL.Image.Image image mode=RGBA size=43x62 at ...>
Export a single layer:
>>> layer_image = layer.as_PIL() >>> layer_image.save('layer.png')
Export the merged image:
>>> merged_image = psd.composite_image() >>> merged_image.save('my_image.png')
Why yet another PSD reader?
There are existing PSD readers for Python:
PIL doesn’t have an API for layer groups, PSD reader in PIL is incomplete and contributing to PIL is somehow complicated because of the slow release process.
GIMP is cool, but it is a huge dependency, its PSD parser is not perfect and it is not easy to use GIMP Python plugin from your code.
I also considered contributing to pypsd or psdparse, but they are GPL and I was not totally satisfied with the interface and the code (they are really fine, that’s me having specific style requirements).
So I finally decided to roll out yet another implementation that should be MIT-licensed, systematically based on the specification; parser should be implemented as a set of functions; the package should also have tests and support both Python 2.x and Python 3.x.
Design overview
The process of handling a PSD file is splitted into 3 stages:
“Reading”: the file is read and parsed to low-level data structures that closely match the specification. No PIL 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 necessary 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”: PIL images of the PSD layers are created and combined to a user-friendly data structure.
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 (e.g. without PIL) based on lower-level decoded PSD file.
Contributing
Development happens at github and bitbucket:
The main issue tracker is at github: https://github.com/kmike/psd-tools/issues
Feel free to submit ideas, bugs, pull requests (git or hg) or regular patches.
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, install tox and type
tox
from the source checkout.
The license is MIT.
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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file psd-tools-0.1.3.tar.gz
.
File metadata
- Download URL: psd-tools-0.1.3.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4cfd26b72c8ea0c566d5e90d6c536130400184a62b7da70bbab33772145bbb2 |
|
MD5 | f4c51744ecde5e46869ac037c398693d |
|
BLAKE2b-256 | ee2511a0a377bba54ab67f3b920db00285d0e3ebaa9fb234340fff22f3717ddb |