How to Inspect PSD Document Sections in Python
A loaded PsdImage exposes read-only summary objects for the structural
sections of a PSD/PSB document — the header, the color data section, the
image data section, and the image resources section — without requiring
any manual byte-level parsing.
Step-by-Step Guide
Step 1: Install the Package
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:$PYTHONPATHStep 2: Import Required Classes
from aspose_psd_foss.psdimage import PsdImageStep 3: Inspect the Header Section
PsdImage.header returns a PsdHeader with the document’s raw structural
fields:
image = PsdImage.load("input.psd")
header = image.header
print(f"Size: {header.width}x{header.height}, channels: {header.channels}")
print(f"Bit depth: {header.bit_depth}, raw color mode: {header.color_mode}")
print(f"Is PSB: {header.is_large_document}")PsdHeader.color_mode returns the raw integer color mode field as stored
in the file — use PsdImage.color_mode instead if you need the strongly
typed ColorModes enum.
Step 4: Inspect the Color Data Section
PsdImage.color_data_info returns a PsdColorDataInfo summary; kind is
a PsdColorDataKind value (NONE, INDEXED_PALETTE, RGB_PAYLOAD,
CMYK_PAYLOAD, or RAW_PRESERVED):
if image.has_color_mode_data:
color_info = image.color_data_info
print(f"Color data kind: {color_info.kind}, raw bytes: {color_info.raw_data_length}")
if color_info.indexed_palette is not None:
print(f"Indexed palette entries: {len(color_info.indexed_palette.entries)}")Step 5: Inspect the Image Data Section
PsdImage.image_data_info returns a PsdImageDataInfo summary describing
how the merged pixel data is encoded:
data_info = image.image_data_info
print(f"Compression: {image.compression}")
print(f"Data kind: {data_info.kind}, uses prediction: {data_info.uses_prediction}")
print(f"Compressed payload length: {data_info.compressed_payload_length}")data_info.kind is an ImageDataKind value (RAW, RLE, ZIP, or
UNKNOWN) describing the merged image data’s own encoding — image.compression
reports the same encoding via the separate CompressionMethod enum.
Step 6: Inspect the Image Resources Section
print(f"Has image resources: {image.has_image_resources}")
print(f"Resource count: {image.resource_count}")
for resource in image.resources:
print(f"Resource ID: {resource.resource_id}, kind: {resource.kind}")PsdImage.resources returns read-only PsdResourceInfo summaries. The
separate PsdImage.image_resources property also has a getter, but its
setter raises NotSupportedException in this FOSS build — see
Troubleshooting for the full list of read-only
setters.
Common Issues and Fixes
header.color_mode doesn’t match image.color_mode. This is expected
— PsdHeader.color_mode is the raw integer field from the file, while
PsdImage.color_mode is the strongly typed ColorModes enum built from it.
color_data_info.indexed_palette is None. The document’s color data
kind is not INDEXED_PALETTE — only indexed-color documents carry a
palette.
Setting image.image_resources raises NotSupportedException. This
setter is not supported in this FOSS build; treat image_resources and
resources as read-only.
Frequently Asked Questions
Can I modify the header, color data, or image data sections directly?
No — PsdHeader, PsdColorDataInfo, ColorData, and PsdImageDataInfo
are all read-only summary objects in this FOSS build. There are no public
setters on any of their properties.
What’s the difference between image.compression and image.image_data_kind?
They describe the same underlying encoding through two separate enums:
image.compression returns a CompressionMethod value, while
image.image_data_info.kind returns an ImageDataKind value.