Resources

Resources

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.


Listing Resource Blocks

PsdImage.image_resources returns a PreservedResourceBlock per resource, with the raw resource ID, name, and byte size:

from aspose_psd_foss.psdimage import PsdImage
from aspose_psd_foss.resources.imageresourceids import ImageResourceIds

image = PsdImage.load(input_path)

for block in image.image_resources:
    print(f"ID: {block.id}, name: {block.name!r}, size: {block.size} bytes")

PsdImage.resources returns a separate PsdResourceInfo summary per resource instead, adding a kind classification — in this FOSS build kind is always PsdResourceKind.UNKNOWN, since this build’s resource parser does not decode specific resource IDs into semantic properties.


Recognizing Known Resource IDs

Since kind is not semantically resolved, recognize a specific resource by comparing block.id against the 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)")

Reading 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)}")

Tips and Best Practices

  • PsdImage.image_resources’ getter works for listing resources, but its setter raises NotSupportedException — resources are read-only in this FOSS build.
  • PsdImage.has_icc_profile, is_icc_profile_untagged, and global_angle are fixed placeholder values in this FOSS build (always False, None, and 0 respectively) regardless of the loaded document’s actual content — use the resource-ID comparison pattern above if you need to detect these resources yourself.
  • PreservedResourceBlock.save() raises NotImplementedError if called directly — resources round-trip automatically when you call image.save() on the whole document.

Common Issues

IssueCauseFix
image.indexed_palette is NoneThe document’s color data kind is not INDEXED_PALETTEOnly indexed-color documents carry a palette
NotSupportedException setting image.image_resourcesThe setter is not supported in this FOSS buildTreat image_resources as read-only
has_icc_profile / is_icc_profile_untagged / global_angle never changeThese 3 properties are hardcoded placeholder stubs in this FOSS buildCompare block.id against ImageResourceIds instead (see above)

FAQ

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.


API Reference Summary

Class/MethodDescription
PsdImage.image_resourcesRaw resource blocks (PreservedResourceBlock, read-only)
PsdImage.resourcesResource summaries (PsdResourceInfo, kind always UNKNOWN)
PsdImage.indexed_paletteIndexed color palette summary, when present
ImageResourceIdsKnown resource ID constants for comparison against resource_id/id

See Also