Skip to main content

A performant read/write parser of Photoshop Files (*.psd and *.psb)

Project description

PhotoshopAPI

ko-fi

CPP Version PyPI - Version PyPi - Downloads Documentation Status CI Status Test Status Python Wheels

[!NOTE] The PhotoshopAPI is still in early development status which means it is subject to change and will likely include bugs. If you find any please report them to the issues page

About

PhotoshopAPI is a C++20 Library with Python bindings for reading and writing of Photoshop Files (*.psd and *.psb) based on previous works from psd_sdk, pytoshop and psd-tools. As well as the official Photoshop File Format Specification, where applicable. The library is continuously tested for correctness in its core functionality. If you do find a bug please submit an issue to the github page.

The motivation to create another library despite all the other works present is that there isn't a library which has layer editing as a first class citizen while also supporting all bit-depths known to Photoshop (8-bits, 16-bits, 32-bits). This Library aims to create an abstraction between the raw binary file format and the structure that the user interfaces against to provide a more intuitive approach to the editing of Photoshop Files.

Why should you care?

Photoshop itself is unfortunately often slow to read/write files and the built-in tools for automatically/programmatically modifying files suffer this same issue. On top of this, due to the extensive history of the Photoshop File Format, Photoshop files written out by Photoshop itself are often unnecessarily bloated to add backwards compatibility or cross-software compatibility.

The PhotoshopAPI tries to address these issue by allowing the user to read/write/modify Photoshop Files without ever having to enter Photoshop itself which additionally means, no license is required. It is roughly 5-10x faster in reads and 20x faster in writes than photoshop while producing files that are consistently 20-50% lower in size (see the benchmarks section on readthedocs for details). The cost of parsing is paid up front either on read or on write so modifying the layer structure itself is almost instantaneous (except for adding new layers).

Features

Supported:

  • Read and write of *.psd and *.psb files
  • Creating and modifying simple and complex nested layer structures
  • Smart Objects (replacing, warping, extracting)
  • Pixel Masks
  • Modifying layer attributes (name, blend mode etc.)
  • Setting the Display ICC Profile
  • 8-, 16- and 32-bit files
  • RGB, CMYK and Grayscale color modes
  • All compression modes known to Photoshop

Planned:

  • Support for Adjustment Layers
  • Support for Vector Masks
  • Support for Text Layers
  • Indexed, Duotone Color Modes

Not Supported:

  • Files written by the PhotoshopAPI do not contain a valid merged image in order to save size meaning they will not behave properly when opened in third party apps requiring these (such as Lightroom)
  • Lab and Multichannel Color Modes

Python

The PhotoshopAPI comes with Python bindings which can be installed using

$ py -m pip install PhotoshopAPI

alternatively the wheels can be downloaded from the Releases page. For examples on how to use the python bindings please refer to the Python Bindings section on Readthedocs or check out the PhotoshopExamples/ directory on the github page which includes examples for Python as well as C++.

For an even quicker way of getting started check out the Quickstart section!

Documentation

The full documentation with benchmarks, build instructions and code reference is hosted on the PhotoshopAPI readthedocs page.

Requirements

This goes over requirements for usage, for development requirements please visit the docs.

  • A CPU with AVX2 support (this is most CPUs after 2014) will greatly increase performance, if we detect this to not be there we disable this optimization
  • A 64-bit system
  • C++ Library: Linux, Windows or MacOS
  • Python Library1: Linux, Windows, MacOS

The python bindings support python >=3.7 (except for ARM-based MacOS machines which raise this to >=3.10)

1 Currently Linux is supported only as manylinux build and has some features disabled such as timestamps on logging.

Performance

The PhotoshopAPI is built with performance as one of its foremost concerns. Using it should enable you to optimize your pipeline rather than slow it down. It runs fully multithreaded with SIMD instructions to leverage all the computing power your computer can afford.

As the feature set increases this will keep being one of the key requirements. For detailed benchmarks please visit the docs

Below you can find some of the benchmarks comparing the PhotoshopAPI ('PSAPI') against Photoshop in read/write performance

8-bit

Quickstart

The primary struct to familiarize yourself with when using the PhotoshopAPI is the LayeredFile as well as all its Layer derivatives (such as ImageLayer and GroupLayer), all of these are template structs for each of the available bit depths.

To get a feel of what is possible with the API as well as how to use it please refer to PhotoshopExample/ directory. To familiarize yourself with the main concepts, as well as recommended workflows check out the docs or the examples.

If more fine grained control over the binary structure is necessary, one can modify the PhotoshopFile which is what is parsed by the API internally. Do keep in mind that this requires a deep understanding of how the Photoshop File Format works.

Below is a minimal example to get started with opening a PhotoshopFile, removing some layer, and writing the file back out to disk:

C++

using namespace NAMESPACE_PSAPI;

// Initialize some constants that we will need throughout the program
const static uint32_t width = 64u;
const static uint32_t height = 64u;

// Create an 8-bit LayeredFile as our starting point, 8- 16- and 32-bit are fully supported
LayeredFile<bpp8_t> document = { Enum::ColorMode::RGB, width, height };
// Create our individual channels to add to our image layer. Keep in mind that all these 3 channels need to 
// be specified for RGB mode
std::unordered_map <Enum::ChannelID, std::vector<bpp8_t>> channelMap;
channelMap[Enum::ChannelID::Red] = std::vector<bpp8_t>(width * height, 255u);
channelMap[Enum::ChannelID::Green] = std::vector<bpp8_t>(width * height, 0u);
channelMap[Enum::ChannelID::Blue] = std::vector<bpp8_t>(width * height, 0u);

ImageLayer<bpp8_t>::Params layerParams = {};
layerParams.name = "Layer Red";
layerParams.width = width;
layerParams.height = height;

auto layer = std::make_shared<ImageLayer<bpp8_t>>(std::move(channelMap), layerParams);
document.add_layer(layer);

// It is perfectly legal to modify a layers properties even after it was added to the document as attributes
// are only finalized on export
layer->opacity(.5f);

// Convert to PhotoshopFile and write to disk. Note that from this point onwards 
// our LayeredFile instance is no longer usable
LayeredFile<bpp8_t>::write(std::move(document), "WriteSimpleFile.psd");

The same code for reading and writing can also be used to for example LayeredFile::move_layer_ or LayeredFile::add_layer as well as extracting any image data

Python

import os
import numpy as np
import photoshopapi as psapi

# Initialize some constants that we will need throughout the program
width = 64
height = 64
color_mode = psapi.enum.ColorMode.rgb

# Generate our LayeredFile instance
document = psapi.LayeredFile_8bit(color_mode, width, height)

img_data = np.zeros((3, height, width), np.uint8)
img_data[0] = 255
# When creating an image layer the width and height parameter are required if its not a zero sized layer
img_layer = psapi.ImageLayer_8bit(img_data, "Layer Red", width=width, height=height)
document.add_layer(img_layer)

# Similar to the C++ version we can adjust parameters of the layer after it has been added to the document
# as long as it happens before we write to disk
img_layer.opacity = .5

document.write(os.path.join(os.path.dirname(__file__), "WriteSimpleFile.psd"))

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

photoshopapi-0.8.2-cp313-cp313-win_amd64.whl (8.1 MB view details)

Uploaded CPython 3.13Windows x86-64

photoshopapi-0.8.2-cp313-cp313-manylinux_2_34_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

photoshopapi-0.8.2-cp313-cp313-macosx_15_0_arm64.whl (6.9 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

photoshopapi-0.8.2-cp312-cp312-win_amd64.whl (8.1 MB view details)

Uploaded CPython 3.12Windows x86-64

photoshopapi-0.8.2-cp312-cp312-manylinux_2_34_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

photoshopapi-0.8.2-cp312-cp312-macosx_15_0_arm64.whl (6.9 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

photoshopapi-0.8.2-cp311-cp311-win_amd64.whl (8.1 MB view details)

Uploaded CPython 3.11Windows x86-64

photoshopapi-0.8.2-cp311-cp311-manylinux_2_34_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

photoshopapi-0.8.2-cp311-cp311-macosx_15_0_arm64.whl (6.9 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

photoshopapi-0.8.2-cp310-cp310-win_amd64.whl (8.1 MB view details)

Uploaded CPython 3.10Windows x86-64

photoshopapi-0.8.2-cp310-cp310-manylinux_2_34_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

photoshopapi-0.8.2-cp310-cp310-macosx_15_0_arm64.whl (6.9 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

photoshopapi-0.8.2-cp39-cp39-win_amd64.whl (8.1 MB view details)

Uploaded CPython 3.9Windows x86-64

photoshopapi-0.8.2-cp39-cp39-manylinux_2_34_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

photoshopapi-0.8.2-cp38-cp38-win_amd64.whl (8.1 MB view details)

Uploaded CPython 3.8Windows x86-64

photoshopapi-0.8.2-cp38-cp38-manylinux_2_34_x86_64.whl (12.5 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.34+ x86-64

File details

Details for the file photoshopapi-0.8.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ec1f85beba7eb97978f0b26c6a3efee4313ef2fafb5014f277ba5ced8e4f46c6
MD5 a8a3d0bf66d3b29345d0e054238f5d86
BLAKE2b-256 328ae86e39dd39abbbbd806384acb7420265da0e9fd5811a7a946c61d38fd7e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp313-cp313-win_amd64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1209943a5c1c08277af801a5facfe0ddb403897c5cecf7827b2576478ef73a64
MD5 d2044847afbe71bf581adfb7101b858d
BLAKE2b-256 0cb3fcb083ea652d090e742642ef7188a837513b8e09f9566ac255e544494383

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 01a781cb5c6def9620aac0ef9cf480d180e9e3aab93d1bcbd8cbe6cb8339b910
MD5 7f339f1425b6e9a3eaeea1b20c3166d9
BLAKE2b-256 d28158e219d97e683e88ccd471f1ed0de5962fa04c2d387179dd86d426fe4a07

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp313-cp313-macosx_15_0_arm64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 095bdd738b7961f152c6accef13cc1140760e7a1c4fcb8dd47baaa03157c4ac8
MD5 0dd5a203023a769c9e000724b30b5d15
BLAKE2b-256 cabb3c1371ee6966912cb091c29e4963eb69fb870b34098ceab71f7282e4cdea

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp312-cp312-win_amd64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 711d4f9df1faa4a6f45bffe07d6008dd4fd0efa8862259b7eecb1c4c82cd16a0
MD5 b8fb50f700758cbdfbc37387150d1a0b
BLAKE2b-256 f3446ccdf7a575a1c9304b867e931af1e7e9325a25db0dcd2f08b17b8fae2831

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 12c007a13bf822d60f385e926adc1e3cca4ad66ad8b400168319318e3e3df860
MD5 4906c666d367ba1fbf430d93e59688c0
BLAKE2b-256 f676bf8a9af57a2b17bb0922dfdeeb8c6af58202078af8481bbbca685f161cf7

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp312-cp312-macosx_15_0_arm64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0ea8bc22f054907460b0f4871f94920a36c296e4dfab26ff65ec879d8f65b449
MD5 2495926e503d4829adfbd4564a421bd5
BLAKE2b-256 8501944b91c8fb8033d7270eaa8e32d78beb857caf817e130a3fdf8428fc7658

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp311-cp311-win_amd64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8d0127f306c4164083363fc66bb0ad8449f02e922c17bc0e6a8dc1667ef03fbe
MD5 4b1451fa0152dda7ed112a1325d4a59c
BLAKE2b-256 76e3715bd3c7718a59c7e71744b1e98acc09dd199e23595d60088d0ac099e4e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 f12af657d823cf6e38923c87bb1dc748d9788df57dd619ede1621e38048f20fc
MD5 ce519b3d4a0b740cbb933f6b99ec90ac
BLAKE2b-256 22750c62057629e1261b0b79e76030db15e8dc8ccb50d3b6445be358ee30e818

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp311-cp311-macosx_15_0_arm64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1b4ca68d83e3c66e495ab32081113046837dbabfc68eeb256ee8d8c3d0d59a12
MD5 5f169d0dde3fc600984d7c89695ef0fb
BLAKE2b-256 763e0c3965c799ecdabc08c56253126c1af6c6fcae5d080fa58abdcdfcf99702

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp310-cp310-win_amd64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e7fae1c48a56fc0c13db891619a23b66549d308371a46a8a759a5ef439bdff58
MD5 43264dad82f25f4a43a3ec954643534d
BLAKE2b-256 ff256de7884bdc514b491494ae41b9754aa6e803446f6f535cdb14411a8cc838

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b65c07478e2b0f3e9f10f82daed03378326f461f1bbb433f6db96d8661591412
MD5 98b843486cf64bdaa86fd7a6c79d44f2
BLAKE2b-256 9b7c85bd6492a6893ea751fc3b000d996f1fafe7448cdf6121de1665511ac73a

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp310-cp310-macosx_15_0_arm64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: photoshopapi-0.8.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 8.1 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for photoshopapi-0.8.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 06644c57e2ccf23e5e24b5e67ac80875ebd7b67442dbda8fbaf79d6359054cf7
MD5 222731a8c36d9d4503d1d08f2ea6edb9
BLAKE2b-256 14c871a1b77dc190f61cbbab76300fc8bcd85569fc00029d3c712529b2078f2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp39-cp39-win_amd64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2050c1dc496f2a9d51c9be9ddf9f008e9c833374d59acf179a32a8842cb92d7c
MD5 109ff5cf0a1aaf4b00d70b9dc94c5d5d
BLAKE2b-256 0ca506f0eee34fb793eb6848bedd0c9d06b742db4c1c668801aaa7e16ac572ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp39-cp39-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: photoshopapi-0.8.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 8.1 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for photoshopapi-0.8.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ecbd1c3aecd5ccf8481b6dde8901efcfe326a033a90987af31191c45e1abb756
MD5 ae57e0bc155916a1aad1fd74b84ed169
BLAKE2b-256 25fb86119229b16ecb18bd258ba41ed62f5598525baa0793a23725e62b8275da

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp38-cp38-win_amd64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file photoshopapi-0.8.2-cp38-cp38-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for photoshopapi-0.8.2-cp38-cp38-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3c77b9713a361c78b0b98991ae7936e891caa07df0838727a9853265184e17b8
MD5 3627b2eb968ab17fbca37b1b2985711d
BLAKE2b-256 c923e7a2648bcb371297a0cd0a33e77db11d92424fba08263ee2fc249515d491

See more details on using hashes here.

Provenance

The following attestation bundles were made for photoshopapi-0.8.2-cp38-cp38-manylinux_2_34_x86_64.whl:

Publisher: build-wheels.yml on EmilDohne/PhotoshopAPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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