Quick Start
Overview
This page walks through the library in the order you will use it: load a document, read it, change layer metadata, and save. It names the exact calls. Runnable code samples are not part of these pages yet; the library repository has sample programs, and every member is listed in the reference.
Step 1: Load a Document
Call PsdImage.load(String) with the path of a PSD or PSB file. To read from a stream, call PsdImage.load(InputStream); it declares the checked PsdLoadException and does not close your stream. Image.load does the same and returns an Image that is a PsdImage for these files. Close the image when you are done, either with close() or by using it in a try-with-resources block.
Step 2: Read the Header
PsdImage reports getWidth(), getHeight(), getBitsPerChannel(), getColorMode(), getCompression() and getChannelsCount(). RGB, CMYK and indexed-color PSD files load, and RGB PSB files load. PsdImage does not tell you whether a file is a PSD or a PSB.
Step 3: Read the Layers
PsdImage.getLayers() returns the Layer objects of the document. Each layer has getName(), isVisible(), getOpacity(), getClipping(), getBlendModeKey() and its position (getLeft(), getTop(), getRight(), getBottom()). getOpacity() returns a byte that holds a value from 0 to 255.
Step 4: Change Layer Metadata
Call setName(String), setVisible(boolean) or setOpacity(byte) on a Layer. The layers belong to the image, so the change is part of the document at once. Layer names are saved as ASCII text of at most 255 characters; read Layers before you edit a document whose layer names contain other characters.
Step 5: Save
Call PsdImage.save(String) to write a file, or PsdImage.save(OutputStream) to write to a stream; save(OutputStream) closes the stream that you pass in. In the library’s own tests, a document saved without changes is identical to the file that was loaded. A document with changed layer metadata contains the changes when you load it again.