How to Work with PSD Image Resources in Python
A loaded PsdImage exposes its image resource blocks — metadata-style
entries such as grids, guides, and ICC profile payloads — through two
read-only views, plus a separate summary for indexed color palettes.
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 PsdImage
from aspose_psd_foss.resources.imageresourceids import ImageResourceIdsStep 3: Check and Count Image Resources
image = PsdImage.load("input.psd")
print(f"Has image resources: {image.has_image_resources}")
print(f"Resource count: {image.resource_count}")Step 4: List Resource Blocks via image_resources
PsdImage.image_resources returns a PreservedResourceBlock per resource,
with the raw resource ID, name, and byte size:
for block in image.image_resources:
print(f"ID: {block.id}, name: {block.name!r}, size: {block.size} bytes")Recognize a specific resource by comparing block.id against the known
constants in ImageResourceIds:
for block in image.image_resources:
if block.id == ImageResourceIds.ICC_PROFILE:
print(f"Found an ICC profile resource ({block.data_size} bytes)")This FOSS build’s resource parser does not decode resource IDs into
semantic properties itself — comparing block.id against ImageResourceIds
yourself is the supported way to recognize a specific resource.
Step 5: List Resource Summaries via resources
PsdImage.resources returns a separate PsdResourceInfo summary per
resource, including a kind classification:
for info in image.resources:
print(f"ID: {info.resource_id}, kind: {info.kind}, data length: {info.data_length}")In this FOSS build, kind is always PsdResourceKind.UNKNOWN — semantic
classification of specific resource kinds (global angle, ICC profile) is
not implemented, so treat kind as informational only and rely on
resource_id (Step 4) to recognize a specific resource.
Step 6: Read an Indexed Color Palette
If the document’s color data is palette-based, PsdImage.indexed_palette
returns its entries:
palette = image.indexed_palette
if palette is not None:
print(f"Palette entries: {len(palette.entries)}")Common Issues and Fixes
image.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. The
getter works for listing resources, but the setter is not supported in
this FOSS build.
Calling block.save() on a PreservedResourceBlock raises
NotImplementedError. Saving individual resource blocks directly is not
supported — resources round-trip automatically when you call
image.save() on the whole document.
has_icc_profile, is_icc_profile_untagged, and global_angle never
change. These three PsdImage properties are fixed placeholder values
in this FOSS build (has_icc_profile is always False,
is_icc_profile_untagged is always None, global_angle is always 0)
regardless of the loaded document’s actual content — this build’s resource
parser does not reconstruct ID-specific semantic values. Use Step 4’s
block.id comparison against ImageResourceIds if you need to detect
these resources yourself.
Frequently Asked Questions
What’s the difference between image_resources and resources?
Both list the same underlying resource blocks, but as different object
types: image_resources returns PreservedResourceBlock objects (raw
ID/name/size, used for round-tripping), while resources returns
PsdResourceInfo summaries (adds a kind classification, currently always
UNKNOWN).
Can I modify or remove an image resource?
No — image_resources’ setter raises NotSupportedException, and
PreservedResourceBlock.save() raises NotImplementedError if called
directly. Resources are read-only in this FOSS build.