MCPcopy Index your code
hub / github.com/chinedufn/psd

github.com/chinedufn/psd @0.3.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.3.4 ↗ · + Follow
290 symbols 640 edges 25 files 97 documented · 33%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

psd

Build status docs

A Rust API for parsing and working with PSD files.

Live Demo

The psd crate can be compiled to WebAssembly and used in a browser.

In the live demo you can visualize a PSD in the browser, toggle layers on and off and drag and drop a new PSD into the demo.

Demo screenshot

Check out the examples/drag-drop-browser directory for instructions on running the demo locally.

The Psd Book

The WIP The Psd Book will contain information about getting started with the psd crate, a description of the architecture and information on how to get started.

API Docs

Check out the API documentation to see everything that you can currently access.

Background / Initial Motivation

I'm working on a game and part of my asset compilation process was a script that did the following:

  1. Iterate over all PSD files

  2. Export every PSD into a PNG, ignoring any layers that begin with an _

  3. Combine PNGs into a texture atlas

For a couple of years I was using imagemagick to power step 2, but after getting a new laptop and upgrading imagemagick versions it stopped working.

After a bit of Googling I couldn't land on a solution for my problem so I decided to make this crate.

My approach was to support as much of the PSD spec as I needed, so there might be bits of information that you'd like to make use of that aren't currently supported.

That said, if there's anything missing that you need please feel very free to open an issue!

Usage

use psd::{ColorMode, Psd, PsdChannelCompression};

fn main () {
    // .. Get a byte slice of PSD file data somehow ..
    let psd = include_bytes!("./my-psd-file.psd");

    let psd = Psd::from_bytes(psd).unwrap();

    assert_eq!(psd.color_mode(), ColorMode::Rgb);

    // For this PSD the final combined image is RleCompressed
    assert_eq!(psd.compression(), &PsdChannelCompression::RleCompressed);

    assert_eq!(psd.width(), 500);
    assert_eq!(psd.height(), 500);

    // Get the combined final image for the PSD.
    let final_image: Vec<u8> = psd.rgba();

    for layer in psd.layers().iter() {
        let name = layer.name();

        let pixels: Vec<u8> = layer.rgba().unwrap();
    }

    let green_layer = psd.layer_by_name("Green Layer").unwrap();

    // In this layer the red channel is uncompressed
    assert_eq!(green_layer.compression(&PsdChannelKind::Red).unwrap(), PsdChannelCompression::RawData);

    // In this layer the green channel is RLE compressed
    assert_eq!(green_layer.compression(&PsdChannelKind::Green).unwrap(), PsdChannelCompression::RleCompressed);

    // Combine the PSD layers top to bottom, ignoring any layers that begin with an `_`
    let pixels: Vec<u8> = psd.flatten_layers_rgba(&|(_idx, layer)| {
        !layer.name().starts_with("_")
    }).unwrap();
}

See Also

License

MIT

Extension points exported contracts — how you extend this code

IntoRgba (Interface)
(no doc) [2 implementers]
src/psd_channel.rs

Core symbols most depended-on inside this repo

push
called by 30
src/sections/layer_and_mask_information_section/groups.rs
read_i32
called by 26
src/sections/mod.rs
layer_by_name
called by 23
src/lib.rs
read
called by 22
src/sections/mod.rs
flatten_layers_rgba
called by 21
src/lib.rs
read_u32
called by 19
src/sections/mod.rs
read_4
called by 17
src/sections/mod.rs
group_by_name
called by 12
tests/layer_and_mask_information_section.rs

Shape

Method 130
Function 108
Class 32
Enum 19
Interface 1

Languages

Rust100%

Modules by API surface

src/sections/layer_and_mask_information_section/layer.rs35 symbols
src/sections/image_resources_section.rs34 symbols
src/blend.rs32 symbols
src/sections/mod.rs31 symbols
src/lib.rs25 symbols
src/sections/file_header_section.rs19 symbols
tests/blend.rs16 symbols
examples/drag-drop-browser/src/lib.rs14 symbols
src/psd_channel.rs12 symbols
tests/layer_and_mask_information_section.rs11 symbols
src/sections/layer_and_mask_information_section/mod.rs8 symbols
tests/compression.rs7 symbols

For agents

$ claude mcp add psd \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact