Introduction

A Photoshop document is a stack of layers, and many tools only need the information about them: names, which ones are visible, how opaque they are. Aspose.PSD FOSS for Java reads this metadata through the Layer class and writes a small set of changes back. This post covers what a Layer shows, what you can change, and where the limits are. The library does not decode layer pixels.


Key Features

Getting the Layers

PsdImage.getLayers() returns a Layer[]. A new array is returned on every call, so keep it if you loop over it. The Layer objects belong to the image: editing one changes the image.

What a Layer Shows

A Layer has getName(), isVisible(), getOpacity(), getClipping(), getBlendModeKey() and the position getLeft(), getTop(), getRight() and getBottom(). getBounds() is not the position: it returns a rectangle at (0, 0) with the layer’s width and height. In the library’s layer-variants.psd test file, for example, one layer is hidden, and another has opacity 191 and a blend mode of LinearBurn. getOpacity() returns a signed byte, so use getOpacity() & 0xFF to get 0 to 255.

Edits That Are Saved

setName(String), setVisible(boolean) and setOpacity(byte) change a layer. Save the document with PsdImage.save and load it again: the new name, visibility and opacity are in the file, and the layer count is unchanged. hasMutated() tells you whether a layer was changed after loading. The position, clipping and blend mode key also have setters; changing the position does not change the layer’s channel data.

Layer Names

Layer names are written as ASCII text of at most 255 characters. A character that is not ASCII is saved as ?, and because saving an edited document rewrites every layer record, the non-ASCII names of layers that you did not edit are saved as ? too. The library updates the layer record’s name only, so other tools may still show the old name if the file keeps a separate Unicode name. Use the edits on files whose layer names are ASCII.

Operations That Are Not Supported

Layer.setChannelInformation, Layer.setLayerMaskData and Layer.setLayerBlendingRangesData always throw UnsupportedOperationException; the getters work. Adding, removing or reordering layers through PsdImage.setLayers is not a supported edit: the saved file keeps the channel data of the original layer list. Passing the same array back to setLayers is accepted, but it counts as a layer edit and the writer then rewrites every layer record. PsdImage.getActiveLayer() returns the first layer (or null when there are no layers), not the layer that was active in Photoshop.


Quick Start

Add the library to your Maven build:

<dependency>
  <groupId>org.aspose</groupId>
  <artifactId>aspose-psd-foss</artifactId>
  <version>26.11.0</version>
</dependency>

Load a file with PsdImage.load, read the layers, call the three setters you need and save. The Layers guide lists every member.


Supported Formats

FormatExtensionReadWrite
PSD.psd✓✓
PSB.psb✓✓

Open Source & Licensing

Aspose.PSD FOSS for Java is MIT licensed. The source is on GitHub and commercial use is allowed.


Getting Started