---
Product: psd
Platform: python
Page Type: kb
Canonical URL: https://kb.aspose.org/psd/python/how-to-work-with-layers-python
Last Updated: 2026-10-08
---

# How to Work with PSD Layers in Python

Read and edit layer metadata — name, visibility, opacity, clipping, and blend mode — using the Layer class in Aspose.PSD FOSS for Python.

This guide shows how to list a document's layers, read and change editable
layer metadata, reposition a layer, and remove a layer from the collection.
A loaded `PsdImage`'s `layers` property returns its collection of `Layer`
objects. Each `Layer` exposes editable metadata — name, visibility, opacity,
clipping, blend mode, and position (bounds edges) — plus read-only overall
bounds and channel information.

## Step-by-Step Guide

### Step 1: Install the Package

```bash
pip install aspose-psd-foss
```

---

### Step 2: Import Required Classes

`PsdImage` loads the document; `BlendMode` is used later to set a layer's
blend mode:

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

---

### Step 3: Load a Document and List Its Layers

Load the document, then iterate `layers` to see each layer's name and
geometry:

```python
image = PsdImage.load("input.psd")

for layer in image.layers:
    print(f"{layer.name}: {layer.width}x{layer.height} at ({layer.left},{layer.top})")
```

---

### Step 4: Read and Edit Layer Visibility, Opacity, and Blend Mode

`is_visible`, `opacity` (conventionally 0-255), `clipping`, `name`, and
`blend_mode_key` all have working setters:

```python
layer = image.layers[0]

layer.is_visible = False          # hide the layer
layer.opacity = 200               # ~78% opacity
layer.blend_mode_key = BlendMode.MULTIPLY
layer.name = "Renamed Layer"
```

---

### Step 5: Read and Reposition Layer Bounds

`bounds`, `width`, `height`, and `channels_count` are read-only — but `top`,
`left`, `bottom`, and `right` each have a working setter that repositions
the layer:

```python
print(f"Bounds: {layer.bounds}")
print(f"Channels: {layer.channels_count}")

layer.left = 10
layer.top = 20
layer.right = 40
layer.bottom = 60
```

---

### Step 6: Replace the Layers Collection

`PsdImage.layers` itself has a working setter, so you can replace the whole
collection (for example, to remove a layer):

```python
image.layers = [l for l in image.layers if l.name != "Renamed Layer"]
```

---

### Step 7: Save the Document

Persist every edit made in the previous steps back to disk, then
release the image's resources:

```python
image.save("output.psd")
image.dispose()
```

## Common Issues and Fixes

**`NotSupportedException` when setting `channel_information`, `layer_mask_data`,
or `layer_blending_ranges_data`.** These three `Layer` setters are not supported
in this FOSS build — treat them as read-only.

**Opacity value looks wrong after setting it.** `opacity` is conventionally a
0-255 value, not a 0.0-1.0 fraction or a percentage — `layer.opacity = 200`
means roughly 78% opaque (200/255).

**Changes to a layer don't appear after saving.** Confirm you are modifying
the `Layer` instance obtained from `image.layers`, and that you call
`image.save()` after making your edits.

## Frequently Asked Questions

### Can I remove a layer from a document?

Yes — `PsdImage.layers` has a working setter, so you can assign it a filtered
list to remove layers (see Step 6).

### What blend modes are available?

`BlendMode` includes values such as `NORMAL`, `MULTIPLY`, `SCREEN`,
`OVERLAY`, and `DARKEN`, among others — set via `Layer.blend_mode_key`.

### Is layer mask data available?

`Layer.layer_mask_data` has a working getter, but its setter raises
`NotSupportedException` in this FOSS build.

## See Also

- [Working with the Core API](../how-to-work-with-psd-core-api-python/)
- [Aspose.PSD FOSS for Python — Frequently Asked Questions](../faq/)
- [Aspose.PSD FOSS for Python developer guide](https://docs.aspose.org/psd/python/developer-guide/)
- [Aspose.PSD — Enterprise Knowledge Base](https://kb.aspose.com/psd/)