Inherits from NSObject
Declared in PSDWriter.h
PSDWriter.m

Tasks

  •   layers

    The PSDLayer objects with layer data, names, etc… Note that when you call createPSDData, this array is slowly emptied – the PSDWriter removes the individual layers from memory as it builds the PSD file.

    property
  •   documentSize

    The size of the PSD you’re exporting.

    property
  •   layerChannelCount

    The number of channels in each layer. Defaults to 4, unless layers are not transparent. At the moment, this setting applies to all layers.

    property
  •   flattenedData

    Optional. The RGBA data for a flattened “preview” of the PSD.

    property
  •   shouldFlipLayerData

    Allows you to automatically vertically flip the image data when it’s being written to PSD. This is important if the source images are coming from OpenGL or another drawing system with an inverted coordinate system.

    property
  •   shouldUnpremultiplyLayerData

    Allows you to automatically unpremultiply the image data. Premultiplication is a process by which the R,G, and B values are multiplied by the alpha. Setting this to YES will cause RGB to be divided by A. You’ll know you need to do this if the image comes out darker than you expect.

    property
  • – initWithDocumentSize:

    Initializes a new PSDWriter for creating a PSD document with the specified size.

  • – addLayerWithCGImage:andName:andOpacity:andOffset:

    Adds a new layer to the PSD image with the provided properties.

Properties

documentSize

The size of the PSD you’re exporting.

@property (nonatomic, assign) CGSize documentSize

Discussion

The size of the PSD you’re exporting.

Declared In

PSDWriter.h

flattenedData

Optional. The RGBA data for a flattened “preview” of the PSD.

@property (nonatomic, retain) NSData *flattenedData

Discussion

Optional. The RGBA data for a flattened “preview” of the PSD.

Declared In

PSDWriter.h

layerChannelCount

The number of channels in each layer. Defaults to 4, unless layers are not transparent. At the moment, this setting applies to all layers.

@property (nonatomic, assign) int layerChannelCount

Discussion

The number of channels in each layer. Defaults to 4, unless layers are not transparent. At the moment, this setting applies to all layers.

Declared In

PSDWriter.h

layers

The PSDLayer objects with layer data, names, etc… Note that when you call createPSDData, this array is slowly emptied – the PSDWriter removes the individual layers from memory as it builds the PSD file.

@property (nonatomic, retain) NSMutableArray *layers

Discussion

The PSDLayer objects with layer data, names, etc… Note that when you call createPSDData, this array is slowly emptied – the PSDWriter removes the individual layers from memory as it builds the PSD file.

Declared In

PSDWriter.h

shouldFlipLayerData

Allows you to automatically vertically flip the image data when it’s being written to PSD. This is important if the source images are coming from OpenGL or another drawing system with an inverted coordinate system.

@property (nonatomic, assign) BOOL shouldFlipLayerData

Discussion

Allows you to automatically vertically flip the image data when it’s being written to PSD. This is important if the source images are coming from OpenGL or another drawing system with an inverted coordinate system.

Declared In

PSDWriter.h

shouldUnpremultiplyLayerData

Allows you to automatically unpremultiply the image data. Premultiplication is a process by which the R,G, and B values are multiplied by the alpha. Setting this to YES will cause RGB to be divided by A. You’ll know you need to do this if the image comes out darker than you expect.

@property (nonatomic, assign) BOOL shouldUnpremultiplyLayerData

Discussion

Allows you to automatically unpremultiply the image data. Premultiplication is a process by which the R,G, and B values are multiplied by the alpha. Setting this to YES will cause RGB to be divided by A. You’ll know you need to do this if the image comes out darker than you expect.

Declared In

PSDWriter.h

Instance Methods

addLayerWithCGImage:andName:andOpacity:andOffset:

Adds a new layer to the PSD image with the provided properties.

- (void)addLayerWithCGImage:(CGImageRef)image andName:(NSString *)name andOpacity:(float)opacity andOffset:(CGPoint)offset

Parameters

image

The image to be added. Does not need to be the same size as the document, but it cannot be larger.

name

The name you’d like to give the layer.

opacity

The opacity of the layer, from [0-1]

offset

The offset of the layer within the document. Use this to position layers within the PSD.

Discussion

Adds a new layer to the PSD image with the provided properties.

If you are using NSImages and not CGImages, use the following code to convert to CGImageRefs:

NSImage* yourImage;
CGImageSourceRef source = CGImageSourceCreateWithData((CFDataRef)[yourImage TIFFRepresentation], NULL);
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(source, 0, NULL);

If you prefer, you can setup PSDLayers by yourself and put them in the PSDWriter.layers array, but this method automatically creates the flattenedData, an image that is a flattened preview of the layered PSD. If you populate the layer objects yourself, you need to provide the flattened image data yourself.

Note: Having layers partially off the edge of the canvas is not currently supported.

Declared In

PSDWriter.h

initWithDocumentSize:

Initializes a new PSDWriter for creating a PSD document with the specified size.

- (id)initWithDocumentSize:(CGSize)s

Parameters

s

The document size

Discussion

Initializes a new PSDWriter for creating a PSD document with the specified size.

Declared In

PSDWriter.h