Layer#

Similar to the C++ bindings this is the base class for all layer types, unlike C++ there is no reason to actually use this type as casting down the inheritance chain is done implicitly. We can however use this to indicate a return type for type hinting.

def some_function() -> psapi.Layer_8bit:
        '''
        Return a layer type
        '''
        pass

This is why we dont actually specify any constructors for the Layer class. If you try and construct a layer object you will get an error

layer = psapi.Layer_8bit() # -> TypeError: psapi.Layer_8bit: No constructor defined!

Similarly the Layer<>::Params class from C++ is not implemented here but rather the arguments are implemented as kwargs for the individual constructors

Class Reference Layer#


class photoshopapi.Layer_8bit#

Base type that all layers inherit from, this class should not be instantiated and instead the derivatives such as psapi.GroupLayer_8bit or psapi.ImageLayer_8bit should be used (with the appropriate bit depth).

Attributes:
namestr

The name of the layer, cannot be longer than 255

masknp.ndarray

The layers’ pixel mask, this is a 2-dimensional array stored in format { height, width }.

blend_modeenum.BlendMode

The blend mode of the layer, ‘Passthrough’ is reserved for group layers

opacityfloat

The layers opacity from 0.0 - 1.0

widthint

The width of the layer ranging up to 30,000 for PSD and 300,000 for PSB, this does not have to match the files width

heightint

The height of the layer ranging up to 30,000 for PSD and 300,000 for PSB, this does not have to match the files height

center_xfloat

The center of the layer in regards to the canvas, a layer at center_x = 0 is perfectly centered around the document

center_yfloat

The center of the layer in regards to the canvas, a layer at center_y = 0 is perfectly centered around the document

is_locked: bool

The locked state of the layer, this locks all pixel channels

is_visible: bool

Whether the layer is visible

clipping_mask: bool

Whether the layer is clipped to the one below.

mask: np.ndarray

The layers’ mask channel, may be empty

mask_disabled: bool

Whether the mask is disabled. Ignored if no mask is present

mask_relative_to_layer: bool

Whether the masks position is relative to the layer. Ignored if no mask is present

mask_default_color: int

The masks’ default color outside of the masks bounding box from 0-255. Ignored if no mask is present

mask_density: int

Optional mask density from 0-255, this is equivalent to layers’ opacity. Ignored if no mask is present

mask_feather: float

Optional mask feather. Ignored if no mask is present

mask_position: psapi.geometry.Point2D

The masks’ canvas coordinates, these represent the center of the mask in terms of the canvas (file). Ignored if no mask is present

mask_width: int

The masks’ width, this does not have to correspond with the layers’ width

mask_height: int

The masks’ height, this does not have to correspond with the layers’ height

has_mask(self: photoshopapi.lib64.photoshopapi.Layer_8bit) bool#

Check whether the layer has an associated mask component (pixel mask)

property mask#

The layers’ pixel mask, this is a 2-dimensional array stored in format { height, width }. A pixel mask may have any dimensions and does not have to match a layers’ width or height. To get the pixel value outside of the masks’ bbox use the mask_default_color property.

property mask_default_color#

The masks’ default color outside of the masks bounding box. Ignored if no mask is present. From 0-255 regardless of bit depth

property mask_density#

Optional mask density from 0-255, this is equivalent to layers’ opacity. Ignored if no mask is present

property mask_disabled#

Whether the mask is disabled. Ignored if no mask is present

property mask_feather#

Optional mask feather. Ignored if no mask is present

mask_height(self: photoshopapi.lib64.photoshopapi.Layer_8bit) int#

The masks’ height in pixels. This does not always have to correspond with the layers’ height.

property mask_position#

The masks’ canvas coordinates, these represent the center of the mask in terms of the canvas (file). Ignored if no mask is present

property mask_relative_to_layer#

Whether the masks position is relative to the layer. Ignored if no mask is present

mask_width(self: photoshopapi.lib64.photoshopapi.Layer_8bit) int#

The masks’ width in pixels. This does not always have to correspond with the layers’ width.

set_mask_compression(self: photoshopapi.lib64.photoshopapi.Layer_8bit, arg0: photoshopapi.lib64.photoshopapi.enum.Compression) None#

Set the masks’ write compression in terms of one of the Photoshop compression codecs. The mask channel may have any compression codec applied to it and this does not need to match the layers’ compression in any way. All compression codecs are valid in the PhotoshopAPI.