psd_tools.api.layers

Layer module.

Group

class psd_tools.api.layers.Group(*args)[source]

Group of layers.

Example:

group = psd[1]
for layer in group:
    if layer.kind == 'pixel':
        print(layer.name)
bbox

(left, top, right, bottom) tuple.

blend_mode

Blend mode of this layer. Writable.

Example:

from psd_tools.constants import BlendMode
if layer.blend_mode == BlendMode.NORMAL:
    layer.blend_mode = BlendMode.SCREEN
Returns:BlendMode.
clip_layers

Clip layers associated with this layer.

To compose clipping layers:

from psd_tools import compose
clip_mask = compose(layer.clip_layers)
Returns:list of layers
compose()

Compose layer and masks (mask, vector mask, and clipping layers).

Returns:PIL Image object, or None if the layer has no pixels.
descendants(include_clip=True)

Return a generator to iterate over all descendant layers.

Example:

# Iterate over all layers
for layer in psd.descendants():
    print(layer)

# Iterate over all layers in reverse order
for layer in reversed(list(psd.descendants())):
    print(layer)
Parameters:include_clip – include clipping layers.
effects

Layer effects.

Returns:Effects
has_clip_layers()

Returns True if the layer has associated clipping.

Returns:bool
has_effects()

Returns True if the layer has effects.

Returns:bool
has_mask()

Returns True if the layer has a mask.

Returns:bool
has_origination()

Returns True if the layer has live shape properties.

Returns:bool
has_pixels()

Returns True if the layer has associated pixels. When this is True, topil method returns PIL.Image.

Returns:bool
has_vector_mask()

Returns True if the layer has a vector mask.

Returns:bool
height

Height of the layer.

Returns:int
is_group()

Return True if the layer is a group.

Returns:bool
is_visible()

Layer visibility. Takes group visibility in account.

Returns:bool
kind

Kind of this layer, either of group, pixel, shape, type, smartobject, or psdimage.

Returns:str
layer_id

Layer ID.

Returns:int layer id. if the layer is not assigned an id, -1.
mask

Returns mask associated with this layer.

Returns:Mask or None
name

Layer name. Writable.

Returns:str
offset

(left, top) tuple. Writable.

Returns:tuple
opacity

Opacity of this layer in [0, 255] range. Writable.

Returns:int
origination

Property for a list of live shapes or a line.

Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.

Returns:List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.
parent

Parent of this layer.

size

(width, height) tuple.

Returns:tuple
topil()

Get PIL Image of the layer.

Returns:PIL.Image, or None if the layer has no pixels.
vector_mask

Returns vector mask associated with this layer.

Returns:VectorMask or None
visible

Layer visibility. Doesn’t take group visibility in account. Writable.

Returns:bool
width

Width of the layer.

Returns:int

PixelLayer

class psd_tools.api.layers.PixelLayer(psd, record, channels, parent)[source]

Layer that has rasterized image in pixels.

Example:

assert layer.kind == 'pixel':
image = layer.topil()
image.save('layer.png')

composed_image = layer.compose()
composed_image.save('composed-layer.png')
bbox

(left, top, right, bottom) tuple.

blend_mode

Blend mode of this layer. Writable.

Example:

from psd_tools.constants import BlendMode
if layer.blend_mode == BlendMode.NORMAL:
    layer.blend_mode = BlendMode.SCREEN
Returns:BlendMode.
bottom

Bottom coordinate.

Returns:int
clip_layers

Clip layers associated with this layer.

To compose clipping layers:

from psd_tools import compose
clip_mask = compose(layer.clip_layers)
Returns:list of layers
compose(*args, **kwargs)

Compose layer and masks (mask, vector mask, and clipping layers).

Returns:PIL.Image, or None if the layer has no pixel.
effects

Layer effects.

Returns:Effects
has_clip_layers()

Returns True if the layer has associated clipping.

Returns:bool
has_effects()

Returns True if the layer has effects.

Returns:bool
has_mask()

Returns True if the layer has a mask.

Returns:bool
has_origination()

Returns True if the layer has live shape properties.

Returns:bool
has_pixels()

Returns True if the layer has associated pixels. When this is True, topil method returns PIL.Image.

Returns:bool
has_vector_mask()

Returns True if the layer has a vector mask.

Returns:bool
height

Height of the layer.

Returns:int
is_group()

Return True if the layer is a group.

Returns:bool
is_visible()

Layer visibility. Takes group visibility in account.

Returns:bool
kind

Kind of this layer, either of group, pixel, shape, type, smartobject, or psdimage.

Returns:str
layer_id

Layer ID.

Returns:int layer id. if the layer is not assigned an id, -1.
left

Left coordinate. Writable.

Returns:int
mask

Returns mask associated with this layer.

Returns:Mask or None
name

Layer name. Writable.

Returns:str
offset

(left, top) tuple. Writable.

Returns:tuple
opacity

Opacity of this layer in [0, 255] range. Writable.

Returns:int
origination

Property for a list of live shapes or a line.

Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.

Returns:List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.
parent

Parent of this layer.

right

Right coordinate.

Returns:int
size

(width, height) tuple.

Returns:tuple
top

Top coordinate. Writable.

Returns:int
topil()

Get PIL Image of the layer.

Returns:PIL.Image, or None if the layer has no pixels.
vector_mask

Returns vector mask associated with this layer.

Returns:VectorMask or None
visible

Layer visibility. Doesn’t take group visibility in account. Writable.

Returns:bool
width

Width of the layer.

Returns:int

ShapeLayer

class psd_tools.api.layers.ShapeLayer(psd, record, channels, parent)[source]

Layer that has drawing in vector mask.

bbox

(left, top, right, bottom) tuple.

blend_mode

Blend mode of this layer. Writable.

Example:

from psd_tools.constants import BlendMode
if layer.blend_mode == BlendMode.NORMAL:
    layer.blend_mode = BlendMode.SCREEN
Returns:BlendMode.
bottom

Bottom coordinate.

Returns:int
clip_layers

Clip layers associated with this layer.

To compose clipping layers:

from psd_tools import compose
clip_mask = compose(layer.clip_layers)
Returns:list of layers
compose(*args, **kwargs)

Compose layer and masks (mask, vector mask, and clipping layers).

Returns:PIL.Image, or None if the layer has no pixel.
effects

Layer effects.

Returns:Effects
has_clip_layers()

Returns True if the layer has associated clipping.

Returns:bool
has_effects()

Returns True if the layer has effects.

Returns:bool
has_mask()

Returns True if the layer has a mask.

Returns:bool
has_origination()

Returns True if the layer has live shape properties.

Returns:bool
has_pixels()

Returns True if the layer has associated pixels. When this is True, topil method returns PIL.Image.

Returns:bool
has_stroke()[source]

Returns True if the shape has a stroke.

has_vector_mask()

Returns True if the layer has a vector mask.

Returns:bool
height

Height of the layer.

Returns:int
is_group()

Return True if the layer is a group.

Returns:bool
is_visible()

Layer visibility. Takes group visibility in account.

Returns:bool
kind

Kind of this layer, either of group, pixel, shape, type, smartobject, or psdimage.

Returns:str
layer_id

Layer ID.

Returns:int layer id. if the layer is not assigned an id, -1.
left

Left coordinate. Writable.

Returns:int
mask

Returns mask associated with this layer.

Returns:Mask or None
name

Layer name. Writable.

Returns:str
offset

(left, top) tuple. Writable.

Returns:tuple
opacity

Opacity of this layer in [0, 255] range. Writable.

Returns:int
origination

Property for a list of live shapes or a line.

Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.

Returns:List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.
parent

Parent of this layer.

right

Right coordinate.

Returns:int
size

(width, height) tuple.

Returns:tuple
stroke

Property for strokes.

top

Top coordinate. Writable.

Returns:int
topil()

Get PIL Image of the layer.

Returns:PIL.Image, or None if the layer has no pixels.
vector_mask

Returns vector mask associated with this layer.

Returns:VectorMask or None
visible

Layer visibility. Doesn’t take group visibility in account. Writable.

Returns:bool
width

Width of the layer.

Returns:int

SmartObjectLayer

class psd_tools.api.layers.SmartObjectLayer(psd, record, channels, parent)[source]

Layer that inserts external data.

Use smart_object attribute to get the external data. See SmartObject.

Example:

import io
if layer.smart_object.filetype == 'jpg':
    image = Image.open(io.BytesIO(layer.smart_object.data))
bbox

(left, top, right, bottom) tuple.

blend_mode

Blend mode of this layer. Writable.

Example:

from psd_tools.constants import BlendMode
if layer.blend_mode == BlendMode.NORMAL:
    layer.blend_mode = BlendMode.SCREEN
Returns:BlendMode.
bottom

Bottom coordinate.

Returns:int
clip_layers

Clip layers associated with this layer.

To compose clipping layers:

from psd_tools import compose
clip_mask = compose(layer.clip_layers)
Returns:list of layers
compose(*args, **kwargs)

Compose layer and masks (mask, vector mask, and clipping layers).

Returns:PIL.Image, or None if the layer has no pixel.
effects

Layer effects.

Returns:Effects
has_clip_layers()

Returns True if the layer has associated clipping.

Returns:bool
has_effects()

Returns True if the layer has effects.

Returns:bool
has_mask()

Returns True if the layer has a mask.

Returns:bool
has_origination()

Returns True if the layer has live shape properties.

Returns:bool
has_pixels()

Returns True if the layer has associated pixels. When this is True, topil method returns PIL.Image.

Returns:bool
has_vector_mask()

Returns True if the layer has a vector mask.

Returns:bool
height

Height of the layer.

Returns:int
is_group()

Return True if the layer is a group.

Returns:bool
is_visible()

Layer visibility. Takes group visibility in account.

Returns:bool
kind

Kind of this layer, either of group, pixel, shape, type, smartobject, or psdimage.

Returns:str
layer_id

Layer ID.

Returns:int layer id. if the layer is not assigned an id, -1.
left

Left coordinate. Writable.

Returns:int
mask

Returns mask associated with this layer.

Returns:Mask or None
name

Layer name. Writable.

Returns:str
offset

(left, top) tuple. Writable.

Returns:tuple
opacity

Opacity of this layer in [0, 255] range. Writable.

Returns:int
origination

Property for a list of live shapes or a line.

Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.

Returns:List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.
parent

Parent of this layer.

right

Right coordinate.

Returns:int
size

(width, height) tuple.

Returns:tuple
smart_object

Associated smart object.

Returns:SmartObject.
top

Top coordinate. Writable.

Returns:int
topil()

Get PIL Image of the layer.

Returns:PIL.Image, or None if the layer has no pixels.
vector_mask

Returns vector mask associated with this layer.

Returns:VectorMask or None
visible

Layer visibility. Doesn’t take group visibility in account. Writable.

Returns:bool
width

Width of the layer.

Returns:int

TypeLayer

class psd_tools.api.layers.TypeLayer(*args)[source]

Layer that has text and styling information for fonts or paragraphs.

Text is accessible at text property. Styling information for paragraphs is in engine_dict. Document styling information such as font list is is resource_dict.

Currently, textual information is read-only.

Example:

if layer.kind == 'type':
    print(layer.text)
    print(layer.engine_dict['StyleRun'])

    # Extract font for each substring in the text.
    text = layer.engine_dict['Editor']['Text'].value
    fontset = layer.resource_dict['FontSet']
    runlength = layer.engine_dict['StyleRun']['RunLengthArray']
    rundata = layer.engine_dict['StyleRun']['RunArray']
    index = 0
    for length, style in zip(runlength, rundata):
        substring = text[index:index + length]
        stylesheet = style['StyleSheet']['StyleSheetData']
        font = fontset[stylesheet['Font']]
        print('%r gets %s' % (substring, font))
        index += length
bbox

(left, top, right, bottom) tuple.

blend_mode

Blend mode of this layer. Writable.

Example:

from psd_tools.constants import BlendMode
if layer.blend_mode == BlendMode.NORMAL:
    layer.blend_mode = BlendMode.SCREEN
Returns:BlendMode.
bottom

Bottom coordinate.

Returns:int
clip_layers

Clip layers associated with this layer.

To compose clipping layers:

from psd_tools import compose
clip_mask = compose(layer.clip_layers)
Returns:list of layers
compose(*args, **kwargs)

Compose layer and masks (mask, vector mask, and clipping layers).

Returns:PIL.Image, or None if the layer has no pixel.
document_resources

Resource set relevant to the document.

effects

Layer effects.

Returns:Effects
engine_dict

Styling information dict.

has_clip_layers()

Returns True if the layer has associated clipping.

Returns:bool
has_effects()

Returns True if the layer has effects.

Returns:bool
has_mask()

Returns True if the layer has a mask.

Returns:bool
has_origination()

Returns True if the layer has live shape properties.

Returns:bool
has_pixels()

Returns True if the layer has associated pixels. When this is True, topil method returns PIL.Image.

Returns:bool
has_vector_mask()

Returns True if the layer has a vector mask.

Returns:bool
height

Height of the layer.

Returns:int
is_group()

Return True if the layer is a group.

Returns:bool
is_visible()

Layer visibility. Takes group visibility in account.

Returns:bool
kind

Kind of this layer, either of group, pixel, shape, type, smartobject, or psdimage.

Returns:str
layer_id

Layer ID.

Returns:int layer id. if the layer is not assigned an id, -1.
left

Left coordinate. Writable.

Returns:int
mask

Returns mask associated with this layer.

Returns:Mask or None
name

Layer name. Writable.

Returns:str
offset

(left, top) tuple. Writable.

Returns:tuple
opacity

Opacity of this layer in [0, 255] range. Writable.

Returns:int
origination

Property for a list of live shapes or a line.

Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.

Returns:List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.
parent

Parent of this layer.

resource_dict

Resource set.

right

Right coordinate.

Returns:int
size

(width, height) tuple.

Returns:tuple
text

Text in the layer. Read-only.

Note

New-line character in Photoshop is ‘\r’.

top

Top coordinate. Writable.

Returns:int
topil()

Get PIL Image of the layer.

Returns:PIL.Image, or None if the layer has no pixels.
transform

Matrix (xx, xy, yx, yy, tx, ty) applies affine transformation.

vector_mask

Returns vector mask associated with this layer.

Returns:VectorMask or None
visible

Layer visibility. Doesn’t take group visibility in account. Writable.

Returns:bool
warp

Warp configuration.

width

Width of the layer.

Returns:int