Introduction

PsdImage is the class you start with in Aspose.PSD FOSS for Java. It represents a document that can be loaded, inspected and saved without rendering. This post goes through its load, header and save members and the behaviour you can rely on. The library is MIT licensed and has no third-party runtime dependency.


Key Features

Loading From a Path or a Stream

PsdImage.load(String) opens a file and PsdImage.load(InputStream) reads a stream. Image.load does the same through the base class and returns an Image that is a PsdImage for these files. Both document types load through the same calls, and PsdImage does not tell you which one a file is. For a stream that supports mark and reset, such as a ByteArrayInputStream, the position is restored after loading, and load does not close the stream that you pass in.

Reading the Header

getWidth(), getHeight(), getBitsPerChannel(), getColorMode(), getCompression() and getChannelsCount() describe the document. In the library’s test files these report, for example, a 200 by 200 RGB document with RLE compression and three channels. getLayers() returns the layers and getImageResources() returns the image resource blocks as read-only data.

Errors

An invalid signature or header, an empty stream, or data that ends before the end of the image resources or layer sections gives a PsdLoadException from load(InputStream). From load(String) the same problems arrive as a RuntimeException that wraps it. A missing file is a FileNotFoundException and a null path is an IllegalArgumentException. PsdLoadException extends Exception, so catch (IOException) does not catch it. The loader does not check the merged image data at the end of the file, so a file that is cut off or damaged only there still loads.

Saving

save(String) and save(OutputStream) write the document. In the library’s own tests, a document that is saved without changes has the same bytes as the file that was loaded. save(OutputStream) closes the stream you pass in. save declares only IOException; a layer name that is longer than 255 characters surfaces as a RuntimeException whose cause is a PsdSaveException.

Behaviour to Know About

getVersion() returns the number 6 for every document, so it cannot be used to tell the two file types apart, and getActiveLayer() returns the first layer. setActiveLayer, setImageResources, setGlobalLayerResources and setHasTransparencyData always throw UnsupportedOperationException. After close(), the getters still work and save throws an IllegalStateException.

Rendering, export and pixel decoding are outside what the library offers.


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>

Call PsdImage.load, read the header, and call save. The Core API guide has the full list of members and errors.


Supported Formats

FormatExtensionReadWrite
PSD.psd✓✓
PSB.psb✓✓

Open Source & Licensing

The library is MIT licensed. The source is on GitHub, and commercial use is allowed.


Getting Started