Struct psd::Psd

source ·
pub struct Psd { /* private fields */ }
Expand description

Represents the contents of a PSD file

PSB Support

We do not currently support PSB since the original authors didn’t need it, but adding support should be trivial. If you’d like to support PSB please open an issue.

Implementations§

source§

impl Psd

source

pub fn from_bytes(bytes: &[u8]) -> Result<Psd, PsdError>

Create a Psd from a byte slice.

You’ll typically get these bytes from a PSD file.

Example
let psd_bytes = include_bytes!("./my-psd-file.psd");

let psd = Psd::from_bytes(psd_bytes);
source§

impl Psd

source

pub fn width(&self) -> u32

The width of the PSD file

source

pub fn height(&self) -> u32

The height of the PSD file

source

pub fn depth(&self) -> PsdDepth

The number of bits per channel

source

pub fn color_mode(&self) -> ColorMode

The color mode of the file

source§

impl Psd

source

pub fn layers(&self) -> &Vec<PsdLayer>

Get all of the layers in the PSD

source

pub fn layer_by_name(&self, name: &str) -> Option<&PsdLayer>

Get a layer by name

source

pub fn layer_by_idx(&self, idx: usize) -> &PsdLayer

Get a layer by index.

index 0 is the bottom layer, index 1 is the layer above that, etc

source

pub fn groups(&self) -> &HashMap<u32, PsdGroup>

Get all of the groups in the PSD, in the order that they appear in the PSD file.

source

pub fn group_ids_in_order(&self) -> &Vec<u32>

Get the group ID’s in the order that they appear in Photoshop. (i.e. from the bottom of layers view to the top of the layers view).

source

pub fn get_group_sub_layers(&self, id: &u32) -> Option<&[PsdLayer]>

Returns sub layers of group by group id

source

pub fn flatten_layers_rgba( &self, filter: &dyn Fn((usize, &PsdLayer)) -> bool ) -> Result<Vec<u8>, PsdError>

Given a filter, combine all layers in the PSD that pass the filter into a vector of RGBA pixels.

We’ll start from the top most layer and iterate through the pixels.

If the pixel is transparent, recursively blend it with the pixels below it until we hit an opaque pixel or we hit the bottom of the stack.

TODO: Take the layer’s blend mode into account when blending layers. Right now we just use ONE_MINUS_SRC_ALPHA blending regardless of the layer.

source§

impl Psd

source

pub fn rgba(&self) -> Vec<u8>

Get the RGBA pixels for the PSD [ R,G,B,A, R,G,B,A, R,G,B,A, …]

source

pub fn compression(&self) -> &PsdChannelCompression

Get the compression level for the flattened image data

source§

impl Psd

source

pub fn resources(&self) -> &Vec<ImageResource>

Resources from the image resources section of the PSD file

Trait Implementations§

source§

impl Debug for Psd

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Psd

§

impl Send for Psd

§

impl Sync for Psd

§

impl Unpin for Psd

§

impl UnwindSafe for Psd

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.