Introduction
Aspose.PSD FOSS for Python loads, inspects, and saves PSD and PSB documents through a small set of classes. This post looks at parts of the core API that the introductory post didn’t cover in depth: how Image and PsdImage relate to each other, the geometry value types used throughout the library, and how the library reports load and save errors.
What’s Included
Image and PsdImage
Image is a minimal abstract base class: it defines only load(), which inspects the input and returns a concrete subclass — for PSD/PSB input, that subclass is PsdImage. The full document surface — color_mode, version, layers, compression, bits_per_channel, size, and more — lives on PsdImage itself, not on the Image base.
from aspose_psd_foss.image import Image
from aspose_psd_foss.psdimage import PsdImage
with Image.load("input.psd") as image:
assert isinstance(image, PsdImage)
print(f"ColorMode: {image.color_mode}, Version: {image.version}")
print(f"Size: {image.size}, Layers: {image.layer_count}")
Geometry Value Types
Point, Size, Rectangle, and RectangleF are the value types used for coordinates and extents across the API — Layer.bounds is a Rectangle, and PsdImage.size is a Size. Rectangle carries real geometry methods: contains(), intersect_rect(), union_rect(), inflate(), and from_left_top_right_bottom(), among others.
from aspose_psd_foss.rectangle import Rectangle
layer_bounds = image.layers[0].bounds
fully_inside = layer_bounds.contains(Rectangle(0, 0, 10, 10))
overlap = Rectangle.intersect_rect(layer_bounds, Rectangle(0, 0, 100, 100))
print(f"Contains (0,0,10,10): {fully_inside}, overlap: {overlap}")
Resource Blocks and Exceptions
PsdImage.image_resources returns the parsed list of ResourceBlock objects — each one exposes id, name, data_size, and signature. In this FOSS build, image_resources, global_layer_resources, active_layer, and has_transparency_data can be read but not reassigned — each has a setter that raises NotSupportedException if called, so treat them as read-only even though they appear as ordinary properties.
Load and save errors surface as two dedicated exception types: PsdLoadException when a document can’t be parsed, and PsdSaveException when a document can’t be written back out.
from aspose_psd_foss.psdimage import PsdImage
from aspose_psd_foss.coreexceptions.psdloadexception import PsdLoadException
try:
with PsdImage.load("input.psd") as image:
for resource in image.image_resources:
print(f"Resource {resource.id}: {resource.name} ({resource.data_size} bytes)")
except PsdLoadException as ex:
print(f"Failed to load input.psd: {ex}")
Quick Start
git clone https://github.com/aspose-psd-foss/Aspose.PSD-FOSS-for-Python.git
cd Aspose.PSD-FOSS-for-Python
# No packaging manifest is published yet -- run from this folder,
# or add it to PYTHONPATH:
export PYTHONPATH=$PWD:$PYTHONPATHfrom aspose_psd_foss.psdimage import PsdImage
from aspose_psd_foss.coreexceptions.psdloadexception import PsdLoadException
try:
with PsdImage.load("input.psd") as image:
print(f"Size: {image.size}, ColorMode: {image.color_mode}")
print(f"ImageResources: {image.resource_count}")
except PsdLoadException as ex:
print(f"Load failed: {ex}")
Supported Formats
| Format | Extension | Read | Write |
|---|---|---|---|
| PSD | psd | ✓ | ✓ |
| PSB | psb | ✓ | ✓ |
Open Source & Licensing
Aspose.PSD FOSS for Python is MIT licensed and may be used in commercial products without royalties, with no evaluation watermark or usage limit.
The library has zero third-party native dependencies — only the Python standard library is required at runtime.