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
  • Pixel Masks
  • Modifying layer attributes (name, blend mode, image data etc.)
  • Setting the Display ICC Profile
  • Setting the DPI of the document
  • 8-, 16- and 32-bit files
  • RGB, CMYK and Grayscale color modes
  • All compression modes known to Photoshop

Planned:

  • Support for Adjustment Layers (planned v0.6.0)
  • Support for Vector Masks
  • Support for Text Layers
  • Support for Smart Object Layers (planned v0.6.0)
  • Indexed and 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 fully fledged Python bindings which can be simply 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 PhotoshopAPI;

// Initialize an 8-bit layeredFile. This must match the bit depth of the PhotoshopFile.
// To initialize this programmatically please refer to the ExtendedSignature example
LayeredFile<bpp8_t> layeredFile = LayeredFile<bpp8_t>::read("InputFile.psd");

// Do some operation, in this case delete
layeredFile.removeLayer("SomeGroup/SomeNestedLayer");	

// One could write out to .psb instead if wanted and the PhotoshopAPI will take 
// care of any conversion internally
LayeredFile<bpp8_t>::write(std::move(layeredFile), "OutputFile.psd");

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

Python

import psapi

# Read the layered_file using the LayeredFile helper class, this returns a 
# psapi.LayeredFile_*bit object with the appropriate bit-depth
layered_file = psapi.LayeredFile.read("InputFile.psd")

# Do some operation, in this case delete
layered_file.remove_layer()

# Write back out to disk
layered_file.write("OutFile.psd")

We can also do much more advanced things such as taking image data from one file and transferring it to another file, this can be across file sizes, psd/psb and even bit-depth!

import psapi
import numpy as np
import os


def main() -> None:
    # Read both our files, they can be open at the same time or we can also read one file,
    # extract the layer and return just that layer if we want to save on RAM.
    file_src = psapi.LayeredFile.read("GraftSource_16.psb")
    file_dest = psapi.LayeredFile.read("GraftDestination_8.psd")

    # Extract the image data and convert to 8-bit.
    lr_src: psapi.ImageLayer_16bit = file_src["GraftSource"]
    img_data_src = lr_src.get_image_data()
    img_data_8bit = {}
    for key, value in img_data_src.items():
        value = value / 256 # Convert from 0-65535 -> 0-255
        img_data_8bit[key] = value.astype(np.uint8)

    # Reconstruct an 8bit converted layer
    img_layer_8bit = psapi.ImageLayer_8bit(
        img_data_8bit, 
        layer_name=lr_src.name, 
        width=lr_src.width, 
        height=lr_src.height, 
        blend_mode=lr_src.blend_mode, 
        opacity=lr_src.opacity
        )

    # add the layer and write out to file!
    file_dest.add_layer(img_layer_8bit)
    file_dest.write("GraftDestination_8_Edited.psd")


if __name__ == "__main__":
    main()

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

photoshopapi-0.5.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distributions

PhotoshopAPI-0.5.1-cp312-cp312-win_amd64.whl (942.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

PhotoshopAPI-0.5.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

PhotoshopAPI-0.5.1-cp312-cp312-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

PhotoshopAPI-0.5.1-cp311-cp311-win_amd64.whl (941.4 kB view details)

Uploaded CPython 3.11 Windows x86-64

PhotoshopAPI-0.5.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

PhotoshopAPI-0.5.1-cp311-cp311-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

PhotoshopAPI-0.5.1-cp310-cp310-win_amd64.whl (940.9 kB view details)

Uploaded CPython 3.10 Windows x86-64

PhotoshopAPI-0.5.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

PhotoshopAPI-0.5.1-cp310-cp310-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

PhotoshopAPI-0.5.1-cp39-cp39-win_amd64.whl (929.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

PhotoshopAPI-0.5.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

PhotoshopAPI-0.5.1-cp38-cp38-win_amd64.whl (940.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

PhotoshopAPI-0.5.1-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

PhotoshopAPI-0.5.1-cp37-cp37m-win_amd64.whl (938.4 kB view details)

Uploaded CPython 3.7m Windows x86-64

PhotoshopAPI-0.5.1-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.27+ x86-64 manylinux: glibc 2.28+ x86-64

File details

Details for the file photoshopapi-0.5.1.tar.gz.

File metadata

  • Download URL: photoshopapi-0.5.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for photoshopapi-0.5.1.tar.gz
Algorithm Hash digest
SHA256 5fe0dae51c22479cee54d67b2595f0ed665790a7d6dc6f6b201c4f81e607492f
MD5 62a1b68dafeeac961b62ef85176ace44
BLAKE2b-256 89375023dfc453f55f8125a5eef4ca8ae44bfc12ea47a2c64ef9a862bb3dcdb4

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4f9e9357deca2c4d8be11cbba27397fc8a14abad10feed64961aa3e83d25c7dc
MD5 3283ba8d1d4fd678ed55e7fbef1a42dd
BLAKE2b-256 ed404e9aaa37cb3b16318f7b4b2b19984452be4b6acad593b6e8c2d526992b41

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 36636bed7fe95ed6fd2dba804a1c9482fd5cb1a9d609239f987a75d3dd430d50
MD5 fc2a8faa68cce9bbcf5ab8f81c13f34b
BLAKE2b-256 95aea13a47029a74ae209842dccb08c50c329328893f0df2e42b0f2f4eef6e7f

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e07a32db9e15f2d2e77eca0dace3182685a7dee52ad466051cd3ac445cd2e08
MD5 68e9cf00f777d58dc4e64f9158c2ab3a
BLAKE2b-256 7fc37fb9dea949d4fee89c2740b5cbca57ea67522490c56ba51995fb0b695e63

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 452f07371e5547d2e8cb88ed093ad8196305778f3c239bd8f641ea82e072e06a
MD5 1606c8911b0fea7b15909a00cb750b2a
BLAKE2b-256 35fdfdfe4d0bf2c2844c3a47aa232440156be3636faf3015d6c2f810d02d6d1b

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3116250b9d92924b0af5f3f501095f0ea7a0ca615466d5969e57b28358e8ccce
MD5 20f9db157527c6ba38d0cc3fb6ea8100
BLAKE2b-256 d7640f4fae429f00d9714c7fc1903f616673dac620b9b8d50f76e597612a9bfe

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 495f726ed6b40f25c84605d1fe3df36056b8bf51a1058d27a341e6052e4dd3c9
MD5 a76f14d97c2b474d834d1dc381af861d
BLAKE2b-256 32fd550eff91ebe2dc0ba6cce068ca43e4ff85bdb8e6804cba11472d4d53ff6a

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 12061ab1f9febdf74f8973c4da630a7605e5bb4611b433adc00656b01c6ee08d
MD5 d1c6bebee584bfb0d8d2113f9203f0a2
BLAKE2b-256 46bca16a8e1831eb9c8669b9169d9fec39b5b36bcdcff054e268783e5b8e99cf

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e0135384125f04f590a8ae4903877244e50a7eafed9bf30d3a029de24bc9b838
MD5 c671d070bdc2dfd7526bb8c3e2bfe172
BLAKE2b-256 3a97ad82b453f6842ddacd026e4da930bc02332d38eb082ab7528b50726b8b81

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03b11ef10236ae4a33f07bd8f4bcd8ece1e82864bde17a7512ccb8a72d63f518
MD5 e54b8c167311822205ccd7963c129258
BLAKE2b-256 52c276b614d562fbfd8a0bcd182c3b87e345a896d2b4e467e1d23a23839fbf39

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0b07daaf679710cacfdab3e6596aa19769228a78b8cc3ee8997d008a6ca087a2
MD5 9ec0e2626ebe0632ba9360f40c6e323e
BLAKE2b-256 7bad14718623bab1f47845d00f601ab84cdc58302aac46b3d627894ff923b244

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5faaffe5f1f30e2b8db9667f46431073fce89b9cffd35b5965da321a21a032b1
MD5 2d7a05edce2b1078d0e68c512f676174
BLAKE2b-256 8cc938bbadc71d52ed4d99cebd306c2f3f1c76f654ef5b6b1332ec9f7667a3a0

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 4befe0fc5bf6ffcf4ff77be687295425e0603a15b3e9ad2e709c7b7e8011f4fc
MD5 01f0fc671af4dd9385c05e7a4dd73f9e
BLAKE2b-256 cf39072e1b79ec217c7e237d45389736f8e84858e27cb97aebf4cc4bc2659956

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp38-cp38-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cd5304194d8d91afe205fe768d12adbc67913428c5415a1df9567eb404108eaa
MD5 beed644db29330bc2b3987ae27f589be
BLAKE2b-256 7b3222a3cca2488007f06588525b3ff20c88500ea58123a3250e06e893e91a18

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 c095802f038455a4c84213fe3943eaf0480d6183379b809fe6ca823bdd71cb4e
MD5 514dc0ffe439f578fbc835d6d7b1a9f8
BLAKE2b-256 4fe0fa22275706c00920c55d28b2dd778416e4e56e63358cfba918994a5f87ae

See more details on using hashes here.

File details

Details for the file PhotoshopAPI-0.5.1-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for PhotoshopAPI-0.5.1-cp37-cp37m-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 245c93997e1f6a10a42473747a50d487feed2d8c69e62dd07a27265332c7e1e5
MD5 9e9ef48ca96bee1798fbd6605114ef68
BLAKE2b-256 c3b4a480e39ecbe0626b936d1ecab6273ca0eed2936930cb17563455c40a62ef

See more details on using hashes here.

Supported by

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