Introduction
PsdImage.layers returns every layer in a PSD or PSB document as a list of Layer objects. This post looks specifically at what a Layer exposes: its geometry and visual state, the blend mode and mask flag enumerations, and the metadata classes that describe a layer’s channels, mask, and blending ranges.
What’s Included
The Layer Class
Each Layer carries a name (name), a bounding Rectangle (bounds, with derived width/height/top/left/bottom/right), visibility and compositing state (is_visible, opacity, clipping, blend_mode_key), and a channel count (channels_count). name, is_visible, opacity, clipping, blend_mode_key, and the four bounds edges can all be changed and written back with PsdImage.save().
from aspose_psd_foss.psdimage import PsdImage
with PsdImage.load("input.psd") as image:
for layer in image.layers:
print(f"{layer.name}: {layer.bounds}, "
f"Visible={layer.is_visible}, Opacity={layer.opacity}, "
f"BlendMode={layer.blend_mode_key}")
Blend Modes and Mask Flags
blend_mode_key is a BlendMode enum value — the library defines 29 standard PSD blend modes (NORMAL, MULTIPLY, SCREEN, OVERLAY, DARKEN, LIGHTEN, COLORDODGE, COLORBURN, HARDLIGHT, SOFTLIGHT, DIFFERENCE, EXCLUSION, HUE, SATURATION, COLOR, LUMINOSITY, and others). A separate LayerMaskFlags flag enum (NONE, RELATIVE_TO_LAYER, DISABLED, INVERTED_WHEN_BLENDING, USER_MASK_FROM_RENDERING_OTHER_DATA, USER_OR_VECTOR_MASKS_HAVE_PARAMETERS) describes mask-rendering behavior where a layer has one.
Channel and Mask Metadata
Layer.channel_information returns a list of ChannelInformation objects describing each channel’s ID, compression method, and byte length. Layer.layer_mask_data (a LayerMaskDataShort when present) describes a layer mask’s bounds and flags; Layer.layer_blending_ranges_data exposes the composite and per-channel blend ranges. All three of these properties are read-only in this FOSS build — their setters raise NotSupportedException if called, even though they appear as regular properties.
from aspose_psd_foss.psdimage import PsdImage
with PsdImage.load("input.psd") as image:
layer = image.layers[0]
for channel in layer.channel_information:
print(f"Channel {channel.ChannelID}: {channel.compression_method}, {channel.length} bytes")
if layer.has_mask_data:
mask = layer.layer_mask_data
print(f"Mask bounds: {mask.mask_rectangle}, flags: {mask.flags}")
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
with PsdImage.load("input.psd") as image:
visible_layers = [layer for layer in image.layers if layer.is_visible]
for layer in visible_layers:
print(f"{layer.name}: Opacity={layer.opacity}, BlendMode={layer.blend_mode_key}")
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.