psd_tools.api.adjustments

Adjustment and fill layers.

Example:

if layer.kind == 'brightnesscontrast':
    print(layer.brightness)

if layer.kind == 'gradientfill':
    print(layer.gradient_kind)

Fill layers

Fill layers are similar to ShapeLayer except that the layer might not have an associated vector mask. The layer therefore expands the entire canvas of the PSD document.

Fill layers all inherit from FillLayer.

Example:

if isinstance(layer, psd_tools.layers.FillLayer):
    image = layer.compose()

SolidColorFill

class psd_tools.api.adjustments.SolidColorFill(*args: Any)[source]

Solid color fill.

property bbox: tuple[int, int, int, int]

(left, top, right, bottom) tuple.

property blend_mode: BlendMode

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.

property bottom: int

Bottom coordinate.

Returns:

int

property clip_layers: list[Self]

Clip layers associated with this layer.

Returns:

list of layers

property clipping: bool

Clipping flag for this layer. Writable.

Returns:

bool

property clipping_layer: bool

Deprecated. Use clipping property instead.

composite(viewport: tuple[int, int, int, int] | None = None, force: bool = False, color: float | tuple[float, ...] | ndarray = 1.0, alpha: float | ndarray = 0.0, layer_filter: Callable | None = None, apply_icc: bool = True) Image | None

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

Parameters:
  • viewport – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Default is the layer’s bbox.

  • force – Boolean flag to force vector drawing.

  • color – Backdrop color specified by scalar or tuple of scalar. The color value should be in [0.0, 1.0]. For example, (1., 0., 0.) specifies red in RGB color mode.

  • alpha – Backdrop alpha in [0.0, 1.0].

  • layer_filter – Callable that takes a layer as argument and returns whether if the layer is composited. Default is is_visible().

Returns:

PIL.Image.Image or None.

create_mask(image: Image, top: int | None = None, left: int | None = None, compression: Compression = Compression.RLE) Mask

Create a pixel mask on this layer from a PIL Image.

If the image has an alpha channel (e.g. RGBA, LA), the alpha channel is used as the mask data. Otherwise the image is converted to grayscale (L mode). White (255) means fully unmasked, black (0) means fully masked.

Parameters:
  • image – Source Image for the mask.

  • top – Top offset of the mask. Defaults to the layer’s top.

  • left – Left offset of the mask. Defaults to the layer’s left.

  • compression – Compression algorithm for the mask data.

Returns:

The new Mask.

Raises:

ValueError – If the layer already has a mask.

property data: DescriptorBlock

Color in Descriptor(RGB).

delete_layer() Self

Deprecated: Use layer.parent.remove(layer) instead.

property effects: Effects

Layer effects.

Returns:

Effects

property fill_opacity: int

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

Returns:

int

has_clip_layers(visible: bool = False) bool

Returns True if the layer has associated clipping.

Parameters:

visible – If True, check for visible clipping layers.

Returns:

bool

has_effects(enabled: bool = True, name: str | None = None) bool

Returns True if the layer has effects.

Parameters:
  • enabled – If True, check for enabled effects.

  • name – If given, check for specific effect type.

Returns:

bool

has_mask() bool

Returns True if the layer has a mask.

Returns:

bool

has_origination() bool

Returns True if the layer has live shape properties.

Returns:

bool

has_pixels() bool

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

Returns:

bool

has_stroke() bool

Returns True if the shape has a stroke.

has_vector_mask() bool

Returns True if the layer has a vector mask.

Returns:

bool

property height: int

Height of the layer.

Returns:

int

is_group() bool

Return True if the layer is a group.

Returns:

bool

is_visible() bool

Layer visibility. Takes group visibility in account.

Returns:

bool

property kind: str

Kind of this layer, such as group, pixel, shape, type, smartobject, or psdimage. Class name without layer suffix.

Returns:

str

property layer_id: int

Layer ID.

Returns:

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

property left: int

Left coordinate. Writable.

Returns:

int

lock(lock_flags: int = ProtectedFlags.COMPLETE) None

Locks a layer accordind to the combination of flags.

Parameters:

lockflags – An integer representing the locking state

Example using the constants of ProtectedFlags and bitwise or operation to lock both pixels and positions:

layer.lock(ProtectedFlags.COMPOSITE | ProtectedFlags.POSITION)
property mask: Mask | None

Returns mask associated with this layer.

Returns:

Mask or None

move_down(offset: int = 1) Self

Moves the layer down a certain offset within the group the layer is in.

Parameters:

offset – The number of positions to move the layer down (can be negative).

Raises:
  • ValueError – If layer has no parent or parent is not a group

  • IndexError – If the new index is out of bounds

Returns:

self

move_to_group(group: GroupMixin) Self

Deprecated: Use group.append(layer) instead.

Parameters:

group – The group the current layer will be moved into.

move_up(offset: int = 1) Self

Moves the layer up a certain offset within the group the layer is in.

Parameters:

offset – The number of positions to move the layer up (can be negative).

Raises:
  • ValueError – If layer has no parent or parent is not a group

  • IndexError – If the new index is out of bounds

Returns:

self

property name: str

Layer name. Writable.

Returns:

str

next_sibling(visible: bool = False) Self | None

Next sibling of this layer.

numpy(channel: str | None = None, real_mask: bool = True) ndarray | None

Get NumPy array of the layer.

Parameters:

channel – Which channel to return, can be ‘color’, ‘shape’, ‘alpha’, or ‘mask’. Default is ‘color+alpha’.

Returns:

numpy.ndarray or None if there is no pixel.

property offset: tuple[int, int]

(left, top) tuple. Writable.

Returns:

tuple

property opacity: int

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

Returns:

int

property origination: list[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.

See psd_tools.api.shape.

Returns:

List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.

property parent: GroupMixinProtocol | None

Parent of this layer.

previous_sibling(visible: bool = False) Self | None

Previous sibling of this layer.

property reference_point: tuple[float, float]

Reference point of this layer as (x, y) tuple in the canvas coordinates. Writable.

Reference point is used for transformations such as rotation and scaling.

Returns:

(x, y) tuple

remove_mask() None

Remove the pixel mask from this layer.

Raises:

ValueError – If the layer does not have a mask.

property right: int

Right coordinate.

Returns:

int

property sheet_color: SheetColorType

Color label of this layer in the Photoshop layers panel. Writable.

Returns:

SheetColorType

property size: tuple[int, int]

(width, height) tuple.

Returns:

tuple

property stroke: Stroke | None

Property for strokes.

property tagged_blocks: TaggedBlocks

Layer tagged blocks that is a dict-like container of settings.

See psd_tools.constants.Tag for available keys.

Returns:

TaggedBlocks.

Example:

from psd_tools.constants import Tag
metadata = layer.tagged_blocks.get_data(Tag.METADATA_SETTING)
property top: int

Top coordinate. Writable.

Returns:

int

topil(channel: int | None = None, apply_icc: bool = True) Image | None

Get PIL Image of the layer.

Parameters:
  • channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB image. See ChannelID. When None, the method returns all the channels supported by PIL modes.

  • apply_icc – Whether to apply ICC profile conversion to sRGB.

Returns:

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

Example:

from psd_tools.constants import ChannelID

image = layer.topil()
red = layer.topil(ChannelID.CHANNEL_0)
alpha = layer.topil(ChannelID.TRANSPARENCY_MASK)

Note

Not all of the PSD image modes are supported in PIL.Image.Image. For example, ‘CMYK’ mode cannot include alpha channel in PIL. In this case, topil drops alpha channel.

update_mask(image: Image, top: int | None = None, left: int | None = None, compression: Compression = Compression.RLE) Mask

Update the pixel mask of this layer with a new image.

If the image has an alpha channel (e.g. RGBA, LA), the alpha channel is used as the mask data. Otherwise the image is converted to grayscale (L mode). White (255) means fully unmasked, black (0) means fully masked.

Parameters:
  • image – New source Image for the mask.

  • top – New top offset of the mask. Defaults to current mask top.

  • left – New left offset of the mask. Defaults to current mask left.

  • compression – Compression algorithm for the mask data.

Returns:

The updated Mask.

Raises:

ValueError – If the layer does not have a mask.

property vector_mask: VectorMask | None

Returns vector mask associated with this layer.

Returns:

VectorMask or None

property visible: bool

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

Returns:

bool

property width: int

Width of the layer.

Returns:

int

PatternFill

class psd_tools.api.adjustments.PatternFill(*args: Any)[source]

Pattern fill.

property bbox: tuple[int, int, int, int]

(left, top, right, bottom) tuple.

property blend_mode: BlendMode

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.

property bottom: int

Bottom coordinate.

Returns:

int

property clip_layers: list[Self]

Clip layers associated with this layer.

Returns:

list of layers

property clipping: bool

Clipping flag for this layer. Writable.

Returns:

bool

property clipping_layer: bool

Deprecated. Use clipping property instead.

composite(viewport: tuple[int, int, int, int] | None = None, force: bool = False, color: float | tuple[float, ...] | ndarray = 1.0, alpha: float | ndarray = 0.0, layer_filter: Callable | None = None, apply_icc: bool = True) Image | None

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

Parameters:
  • viewport – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Default is the layer’s bbox.

  • force – Boolean flag to force vector drawing.

  • color – Backdrop color specified by scalar or tuple of scalar. The color value should be in [0.0, 1.0]. For example, (1., 0., 0.) specifies red in RGB color mode.

  • alpha – Backdrop alpha in [0.0, 1.0].

  • layer_filter – Callable that takes a layer as argument and returns whether if the layer is composited. Default is is_visible().

Returns:

PIL.Image.Image or None.

create_mask(image: Image, top: int | None = None, left: int | None = None, compression: Compression = Compression.RLE) Mask

Create a pixel mask on this layer from a PIL Image.

If the image has an alpha channel (e.g. RGBA, LA), the alpha channel is used as the mask data. Otherwise the image is converted to grayscale (L mode). White (255) means fully unmasked, black (0) means fully masked.

Parameters:
  • image – Source Image for the mask.

  • top – Top offset of the mask. Defaults to the layer’s top.

  • left – Left offset of the mask. Defaults to the layer’s left.

  • compression – Compression algorithm for the mask data.

Returns:

The new Mask.

Raises:

ValueError – If the layer already has a mask.

property data: DescriptorBlock

Pattern in Descriptor(PATTERN).

delete_layer() Self

Deprecated: Use layer.parent.remove(layer) instead.

property effects: Effects

Layer effects.

Returns:

Effects

property fill_opacity: int

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

Returns:

int

has_clip_layers(visible: bool = False) bool

Returns True if the layer has associated clipping.

Parameters:

visible – If True, check for visible clipping layers.

Returns:

bool

has_effects(enabled: bool = True, name: str | None = None) bool

Returns True if the layer has effects.

Parameters:
  • enabled – If True, check for enabled effects.

  • name – If given, check for specific effect type.

Returns:

bool

has_mask() bool

Returns True if the layer has a mask.

Returns:

bool

has_origination() bool

Returns True if the layer has live shape properties.

Returns:

bool

has_pixels() bool

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

Returns:

bool

has_stroke() bool

Returns True if the shape has a stroke.

has_vector_mask() bool

Returns True if the layer has a vector mask.

Returns:

bool

property height: int

Height of the layer.

Returns:

int

is_group() bool

Return True if the layer is a group.

Returns:

bool

is_visible() bool

Layer visibility. Takes group visibility in account.

Returns:

bool

property kind: str

Kind of this layer, such as group, pixel, shape, type, smartobject, or psdimage. Class name without layer suffix.

Returns:

str

property layer_id: int

Layer ID.

Returns:

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

property left: int

Left coordinate. Writable.

Returns:

int

lock(lock_flags: int = ProtectedFlags.COMPLETE) None

Locks a layer accordind to the combination of flags.

Parameters:

lockflags – An integer representing the locking state

Example using the constants of ProtectedFlags and bitwise or operation to lock both pixels and positions:

layer.lock(ProtectedFlags.COMPOSITE | ProtectedFlags.POSITION)
property mask: Mask | None

Returns mask associated with this layer.

Returns:

Mask or None

move_down(offset: int = 1) Self

Moves the layer down a certain offset within the group the layer is in.

Parameters:

offset – The number of positions to move the layer down (can be negative).

Raises:
  • ValueError – If layer has no parent or parent is not a group

  • IndexError – If the new index is out of bounds

Returns:

self

move_to_group(group: GroupMixin) Self

Deprecated: Use group.append(layer) instead.

Parameters:

group – The group the current layer will be moved into.

move_up(offset: int = 1) Self

Moves the layer up a certain offset within the group the layer is in.

Parameters:

offset – The number of positions to move the layer up (can be negative).

Raises:
  • ValueError – If layer has no parent or parent is not a group

  • IndexError – If the new index is out of bounds

Returns:

self

property name: str

Layer name. Writable.

Returns:

str

next_sibling(visible: bool = False) Self | None

Next sibling of this layer.

numpy(channel: str | None = None, real_mask: bool = True) ndarray | None

Get NumPy array of the layer.

Parameters:

channel – Which channel to return, can be ‘color’, ‘shape’, ‘alpha’, or ‘mask’. Default is ‘color+alpha’.

Returns:

numpy.ndarray or None if there is no pixel.

property offset: tuple[int, int]

(left, top) tuple. Writable.

Returns:

tuple

property opacity: int

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

Returns:

int

property origination: list[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.

See psd_tools.api.shape.

Returns:

List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.

property parent: GroupMixinProtocol | None

Parent of this layer.

previous_sibling(visible: bool = False) Self | None

Previous sibling of this layer.

property reference_point: tuple[float, float]

Reference point of this layer as (x, y) tuple in the canvas coordinates. Writable.

Reference point is used for transformations such as rotation and scaling.

Returns:

(x, y) tuple

remove_mask() None

Remove the pixel mask from this layer.

Raises:

ValueError – If the layer does not have a mask.

property right: int

Right coordinate.

Returns:

int

property sheet_color: SheetColorType

Color label of this layer in the Photoshop layers panel. Writable.

Returns:

SheetColorType

property size: tuple[int, int]

(width, height) tuple.

Returns:

tuple

property stroke: Stroke | None

Property for strokes.

property tagged_blocks: TaggedBlocks

Layer tagged blocks that is a dict-like container of settings.

See psd_tools.constants.Tag for available keys.

Returns:

TaggedBlocks.

Example:

from psd_tools.constants import Tag
metadata = layer.tagged_blocks.get_data(Tag.METADATA_SETTING)
property top: int

Top coordinate. Writable.

Returns:

int

topil(channel: int | None = None, apply_icc: bool = True) Image | None

Get PIL Image of the layer.

Parameters:
  • channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB image. See ChannelID. When None, the method returns all the channels supported by PIL modes.

  • apply_icc – Whether to apply ICC profile conversion to sRGB.

Returns:

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

Example:

from psd_tools.constants import ChannelID

image = layer.topil()
red = layer.topil(ChannelID.CHANNEL_0)
alpha = layer.topil(ChannelID.TRANSPARENCY_MASK)

Note

Not all of the PSD image modes are supported in PIL.Image.Image. For example, ‘CMYK’ mode cannot include alpha channel in PIL. In this case, topil drops alpha channel.

update_mask(image: Image, top: int | None = None, left: int | None = None, compression: Compression = Compression.RLE) Mask

Update the pixel mask of this layer with a new image.

If the image has an alpha channel (e.g. RGBA, LA), the alpha channel is used as the mask data. Otherwise the image is converted to grayscale (L mode). White (255) means fully unmasked, black (0) means fully masked.

Parameters:
  • image – New source Image for the mask.

  • top – New top offset of the mask. Defaults to current mask top.

  • left – New left offset of the mask. Defaults to current mask left.

  • compression – Compression algorithm for the mask data.

Returns:

The updated Mask.

Raises:

ValueError – If the layer does not have a mask.

property vector_mask: VectorMask | None

Returns vector mask associated with this layer.

Returns:

VectorMask or None

property visible: bool

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

Returns:

bool

property width: int

Width of the layer.

Returns:

int

GradientFill

class psd_tools.api.adjustments.GradientFill(*args: Any)[source]

Gradient fill.

property bbox: tuple[int, int, int, int]

(left, top, right, bottom) tuple.

property blend_mode: BlendMode

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.

property bottom: int

Bottom coordinate.

Returns:

int

property clip_layers: list[Self]

Clip layers associated with this layer.

Returns:

list of layers

property clipping: bool

Clipping flag for this layer. Writable.

Returns:

bool

property clipping_layer: bool

Deprecated. Use clipping property instead.

composite(viewport: tuple[int, int, int, int] | None = None, force: bool = False, color: float | tuple[float, ...] | ndarray = 1.0, alpha: float | ndarray = 0.0, layer_filter: Callable | None = None, apply_icc: bool = True) Image | None

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

Parameters:
  • viewport – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Default is the layer’s bbox.

  • force – Boolean flag to force vector drawing.

  • color – Backdrop color specified by scalar or tuple of scalar. The color value should be in [0.0, 1.0]. For example, (1., 0., 0.) specifies red in RGB color mode.

  • alpha – Backdrop alpha in [0.0, 1.0].

  • layer_filter – Callable that takes a layer as argument and returns whether if the layer is composited. Default is is_visible().

Returns:

PIL.Image.Image or None.

create_mask(image: Image, top: int | None = None, left: int | None = None, compression: Compression = Compression.RLE) Mask

Create a pixel mask on this layer from a PIL Image.

If the image has an alpha channel (e.g. RGBA, LA), the alpha channel is used as the mask data. Otherwise the image is converted to grayscale (L mode). White (255) means fully unmasked, black (0) means fully masked.

Parameters:
  • image – Source Image for the mask.

  • top – Top offset of the mask. Defaults to the layer’s top.

  • left – Left offset of the mask. Defaults to the layer’s left.

  • compression – Compression algorithm for the mask data.

Returns:

The new Mask.

Raises:

ValueError – If the layer already has a mask.

property data: DescriptorBlock

Gradient in Descriptor(GRADIENT).

delete_layer() Self

Deprecated: Use layer.parent.remove(layer) instead.

property effects: Effects

Layer effects.

Returns:

Effects

property fill_opacity: int

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

Returns:

int

property gradient_kind: str

Kind of the gradient, one of the following:

  • Linear

  • Radial

  • Angle

  • Reflected

  • Diamond

has_clip_layers(visible: bool = False) bool

Returns True if the layer has associated clipping.

Parameters:

visible – If True, check for visible clipping layers.

Returns:

bool

has_effects(enabled: bool = True, name: str | None = None) bool

Returns True if the layer has effects.

Parameters:
  • enabled – If True, check for enabled effects.

  • name – If given, check for specific effect type.

Returns:

bool

has_mask() bool

Returns True if the layer has a mask.

Returns:

bool

has_origination() bool

Returns True if the layer has live shape properties.

Returns:

bool

has_pixels() bool

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

Returns:

bool

has_stroke() bool

Returns True if the shape has a stroke.

has_vector_mask() bool

Returns True if the layer has a vector mask.

Returns:

bool

property height: int

Height of the layer.

Returns:

int

is_group() bool

Return True if the layer is a group.

Returns:

bool

is_visible() bool

Layer visibility. Takes group visibility in account.

Returns:

bool

property kind: str

Kind of this layer, such as group, pixel, shape, type, smartobject, or psdimage. Class name without layer suffix.

Returns:

str

property layer_id: int

Layer ID.

Returns:

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

property left: int

Left coordinate. Writable.

Returns:

int

lock(lock_flags: int = ProtectedFlags.COMPLETE) None

Locks a layer accordind to the combination of flags.

Parameters:

lockflags – An integer representing the locking state

Example using the constants of ProtectedFlags and bitwise or operation to lock both pixels and positions:

layer.lock(ProtectedFlags.COMPOSITE | ProtectedFlags.POSITION)
property mask: Mask | None

Returns mask associated with this layer.

Returns:

Mask or None

move_down(offset: int = 1) Self

Moves the layer down a certain offset within the group the layer is in.

Parameters:

offset – The number of positions to move the layer down (can be negative).

Raises:
  • ValueError – If layer has no parent or parent is not a group

  • IndexError – If the new index is out of bounds

Returns:

self

move_to_group(group: GroupMixin) Self

Deprecated: Use group.append(layer) instead.

Parameters:

group – The group the current layer will be moved into.

move_up(offset: int = 1) Self

Moves the layer up a certain offset within the group the layer is in.

Parameters:

offset – The number of positions to move the layer up (can be negative).

Raises:
  • ValueError – If layer has no parent or parent is not a group

  • IndexError – If the new index is out of bounds

Returns:

self

property name: str

Layer name. Writable.

Returns:

str

next_sibling(visible: bool = False) Self | None

Next sibling of this layer.

numpy(channel: str | None = None, real_mask: bool = True) ndarray | None

Get NumPy array of the layer.

Parameters:

channel – Which channel to return, can be ‘color’, ‘shape’, ‘alpha’, or ‘mask’. Default is ‘color+alpha’.

Returns:

numpy.ndarray or None if there is no pixel.

property offset: tuple[int, int]

(left, top) tuple. Writable.

Returns:

tuple

property opacity: int

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

Returns:

int

property origination: list[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.

See psd_tools.api.shape.

Returns:

List of Invalidated, Rectangle, RoundedRectangle, Ellipse, or Line.

property parent: GroupMixinProtocol | None

Parent of this layer.

previous_sibling(visible: bool = False) Self | None

Previous sibling of this layer.

property reference_point: tuple[float, float]

Reference point of this layer as (x, y) tuple in the canvas coordinates. Writable.

Reference point is used for transformations such as rotation and scaling.

Returns:

(x, y) tuple

remove_mask() None

Remove the pixel mask from this layer.

Raises:

ValueError – If the layer does not have a mask.

property right: int

Right coordinate.

Returns:

int

property sheet_color: SheetColorType

Color label of this layer in the Photoshop layers panel. Writable.

Returns:

SheetColorType

property size: tuple[int, int]

(width, height) tuple.

Returns:

tuple

property stroke: Stroke | None

Property for strokes.

property tagged_blocks: TaggedBlocks

Layer tagged blocks that is a dict-like container of settings.

See psd_tools.constants.Tag for available keys.

Returns:

TaggedBlocks.

Example:

from psd_tools.constants import Tag
metadata = layer.tagged_blocks.get_data(Tag.METADATA_SETTING)
property top: int

Top coordinate. Writable.

Returns:

int

topil(channel: int | None = None, apply_icc: bool = True) Image | None

Get PIL Image of the layer.

Parameters:
  • channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB image. See ChannelID. When None, the method returns all the channels supported by PIL modes.

  • apply_icc – Whether to apply ICC profile conversion to sRGB.

Returns:

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

Example:

from psd_tools.constants import ChannelID

image = layer.topil()
red = layer.topil(ChannelID.CHANNEL_0)
alpha = layer.topil(ChannelID.TRANSPARENCY_MASK)

Note

Not all of the PSD image modes are supported in PIL.Image.Image. For example, ‘CMYK’ mode cannot include alpha channel in PIL. In this case, topil drops alpha channel.

update_mask(image: Image, top: int | None = None, left: int | None = None, compression: Compression = Compression.RLE) Mask

Update the pixel mask of this layer with a new image.

If the image has an alpha channel (e.g. RGBA, LA), the alpha channel is used as the mask data. Otherwise the image is converted to grayscale (L mode). White (255) means fully unmasked, black (0) means fully masked.

Parameters:
  • image – New source Image for the mask.

  • top – New top offset of the mask. Defaults to current mask top.

  • left – New left offset of the mask. Defaults to current mask left.

  • compression – Compression algorithm for the mask data.

Returns:

The updated Mask.

Raises:

ValueError – If the layer does not have a mask.

property vector_mask: VectorMask | None

Returns vector mask associated with this layer.

Returns:

VectorMask or None

property visible: bool

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

Returns:

bool

property width: int

Width of the layer.

Returns:

int

Adjustment layers

Adjustment layers apply image filtering to the composed result. All adjustment layers inherit from AdjustmentLayer. Adjustment layers do not have pixels, and currently ignored in compose. Attempts to call topil on adjustment layers always return None.

Just as any other layer, adjustment layers might have an associated mask or vector mask. Adjustment can appear in other layers’ clipping layers.

Example:

if isinstance(layer, psd_tools.layers.AdjustmentLayer):
    print(layer.kind)

BrightnessContrast

class psd_tools.api.adjustments.BrightnessContrast(*args: Any)[source]

Brightness and contrast adjustment.

property automatic: bool
property brightness: int
property contrast: int
property lab: bool
property mean: int
property use_legacy: bool
property vrsn: int

Curves

class psd_tools.api.adjustments.Curves(*args: Any)[source]

Curves adjustment.

property data: Curves

Raw data.

Returns:

Curves

property extra: Any

Exposure

class psd_tools.api.adjustments.Exposure(*args: Any)[source]

Exposure adjustment.

property exposure: float

Exposure.

Returns:

float

property exposure_offset: float

Exposure offset.

Returns:

float

property gamma: float

Gamma.

Returns:

float

Levels

class psd_tools.api.adjustments.Levels(*args: Any)[source]

Levels adjustment.

Levels contain a list of LevelRecord.

property data: Levels

List of level records. The first record is the master.

Returns:

Levels.

property master: LevelRecord

Master record.

Vibrance

class psd_tools.api.adjustments.Vibrance(*args: Any)[source]

Vibrance adjustment.

property saturation: int

Saturation.

Returns:

int

property vibrance: int

Vibrance.

Returns:

int

HueSaturation

class psd_tools.api.adjustments.HueSaturation(*args: Any)[source]

Hue/Saturation adjustment.

HueSaturation contains a list of data.

property colorization: tuple

Colorization.

Returns:

tuple

property data: list

List of Hue/Saturation records.

Returns:

list

property enable_colorization: int

Enable colorization.

Returns:

int

property master: tuple

Master record.

Returns:

tuple

ColorBalance

class psd_tools.api.adjustments.ColorBalance(*args: Any)[source]

Color balance adjustment.

property highlights: tuple

Highlights.

Returns:

tuple

property luminosity: int

Luminosity.

Returns:

int

property midtones: tuple

Mid-tones.

Returns:

tuple

property shadows: tuple

Shadows.

Returns:

tuple

BlackAndWhite

class psd_tools.api.adjustments.BlackAndWhite(*args: Any)[source]

Black and white adjustment.

property blue: int
property cyan: int
property green: int
property magenta: int
property preset_file_name: str
property preset_kind: int
property red: int
property tint_color: Any
property use_tint: bool
property yellow: int

PhotoFilter

class psd_tools.api.adjustments.PhotoFilter(*args: Any)[source]

Photo filter adjustment.

property color_components: Any
property color_space: Any
property density: Any
property luminosity: Any
property xyz: bool

xyz.

Returns:

bool

ChannelMixer

class psd_tools.api.adjustments.ChannelMixer(*args: Any)[source]

Channel mixer adjustment.

property data: Any
property monochrome: Any

ColorLookup

class psd_tools.api.adjustments.ColorLookup(*args: Any)[source]

Color lookup adjustment.

Posterize

class psd_tools.api.adjustments.Posterize(*args: Any)[source]

Posterize adjustment.

property posterize: int

Posterize value.

Returns:

int

Threshold

class psd_tools.api.adjustments.Threshold(*args: Any)[source]

Threshold adjustment.

property threshold: int

Threshold value.

Returns:

int

SelectiveColor

class psd_tools.api.adjustments.SelectiveColor(*args: Any)[source]

Selective color adjustment.

property data: Any
property method: Any

GradientMap

class psd_tools.api.adjustments.GradientMap(*args: Any)[source]

Gradient map adjustment.

property color_model: Any
property color_stops: Any
property dithered: Any
property expansion: Any
property gradient_name: Any
property interpolation: float

Interpolation between 0.0 and 1.0.

property length: Any
property max_color: Any
property min_color: Any
property mode: Any
property random_seed: Any
property reversed: Any
property roughness: Any
property show_transparency: Any
property transparency_stops: Any
property use_vector_color: Any