---
Product: psd
Platform: python
Page Type: docs
Canonical URL: https://docs.aspose.org/psd/python/developer-guide/layers
---

# Layers

How to read and edit layer metadata with the Layer class: geometry, visibility and compositing state, channel information, mask data, and blending ranges.

## Overview

`PsdImage.layers` returns every parsed layer as a list of `Layer` objects. Each `Layer` exposes its own geometry, visibility and compositing state, and metadata about its channels, mask, and blending ranges.

---

### Reading Layer Metadata

`name`, `bounds` (and the derived `width`/`height`/`top`/`left`/`bottom`/`right`), `is_visible`, `opacity`, `clipping`, `blend_mode_key`, and `channels_count` are all readable directly.

```python
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}")
```

---

### Supported Metadata Edits

`name`, `is_visible`, `opacity`, `clipping`, `blend_mode_key`, and the four bounds edges (`top`/`left`/`bottom`/`right`) can be changed in place and written back with `PsdImage.save()`.

```python
from aspose_psd_foss.psdimage import PsdImage
from aspose_psd_foss.layers.blendmode import BlendMode

with PsdImage.load("input.psd") as image:
    layer = image.layers[0]
    layer.name = f"{layer.name} (edited)"
    layer.is_visible = not layer.is_visible
    layer.opacity = 128
    layer.blend_mode_key = BlendMode.MULTIPLY
    image.save("output.psd")
```

---

### Channel and Mask Metadata

`channel_information`, `layer_mask_data`, and `layer_blending_ranges_data` are read-only in this FOSS build — their setters raise `NotSupportedException`.

```python
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}")
```

---

### Removing or Reordering Layers

`PsdImage.layers` has a setter as well as a getter: assigning a filtered or reordered list replaces the document's layer collection.

```python
from aspose_psd_foss.psdimage import PsdImage

with PsdImage.load("input.psd") as image:
    image.layers = [layer for layer in image.layers if layer.is_visible]
    image.save("output.psd")
```

---

### Tips and Best Practices

- Index into `image.layers` by position; the list order matches the document's own layer order.
- `blend_mode_key` accepts any `BlendMode` enum value — no validation is performed against the document's declared color mode.
- `channel_information`, `layer_mask_data`, and `layer_blending_ranges_data` can be read but never reassigned.
- Call `PsdImage.save()` once after all edits; each call writes the full document.

---

### Common Issues

| Issue | Cause | Fix |
|---|---|---|
| `NotSupportedException` when setting `channel_information`, `layer_mask_data`, or `layer_blending_ranges_data` | These 3 properties are read-only in the FOSS build despite having a setter | Read the value; do not attempt to reassign it |
| `layer_mask_data` access when there is no mask | Not every layer has a mask subsection | Check `layer.has_mask_data` before reading `layer.layer_mask_data` |

---

### FAQ

#### Can I remove a layer?

Yes — reassign `image.layers` to a filtered list.

#### Can I change a layer's channel or mask data?

No. `channel_information`, `layer_mask_data`, and `layer_blending_ranges_data` are read-only — only `name`, `is_visible`, `opacity`, `clipping`, `blend_mode_key`, and the bounds edges can be changed.

---

### API Reference Summary

| Class/Method | Description |
|---|---|
| `PsdImage.layers` | Gets or sets the layer collection — settable for removal/reordering |
| `Layer.name` / `is_visible` / `opacity` / `clipping` / `blend_mode_key` / `top` / `left` / `bottom` / `right` | Supported layer metadata edits |
| `Layer.bounds` / `width` / `height` / `channels_count` | Read-only layer geometry |
| `Layer.channel_information` / `layer_mask_data` / `layer_blending_ranges_data` | Read-only channel/mask/blending metadata |

## See Also

- [Aspose.PSD — Enterprise Documentation](https://docs.aspose.com/psd/)