GroupLayer#

As with LayeredFile, we only provide documentation for the 8bit type here but 16- and 32-bit are both equally supported, all the classes can be seen below.

GroupLayer_8bit

GroupLayer_16bit

GroupLayer_32bit

Similar to the LayeredFile, we can access child layers using the __getitem__ function with dict-like indexing []. As long as the names of these layers are valid we can chain as many of these as we want.

group_layer = # group_layer instance with some child nodes
image_layer = group_layer["NestedGroup"]["MoreNested"]["ImageLayer"]

# We could also combine this with the channel indexing of the ImageLayer:
channel_r = group_layer["NestedGroup"]["MoreNested"]["ImageLayer"][0]
# or
channel_r = group_layer["NestedGroup"]["MoreNested"]["ImageLayer"][psapi.enum.ChannelID.red]

Class Reference GroupLayer#


class photoshopapi.GroupLayer_8bit#
Attributes:
layerslist[psapi.Layer_*bit]

The layers under the group, may be empty. These are polymorphic so it may be a group layer, an image layer etc. Retrieving them will cast them to their appropriate type

is_collapsedbool

Whether or not the group is collapsed or not

namestr

The name of the layer, cannot be longer than 255

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

__init__(self: photoshopapi.lib64.photoshopapi.GroupLayer_8bit, layer_name: str, layer_mask: Optional[numpy.ndarray[numpy.uint8]] = None, width: int = 0, height: int = 0, blend_mode: photoshopapi.lib64.photoshopapi.enum.BlendMode = <BlendMode.passthrough: 0>, pos_x: int = 0, pos_y: int = 0, opacity: float = 1.0, compression: photoshopapi.lib64.photoshopapi.enum.Compression = <Compression.zipprediction: 3>, color_mode: photoshopapi.lib64.photoshopapi.enum.ColorMode = <ColorMode.rgb: 3>, is_collapsed: bool = False, is_visible: bool = True, is_locked: bool = False) None#

Construct a group layer instance

Parameters:
  • layer_name (str) – The name of the group, its length must not exceed 255

  • layer_mask (numpy.ndarray) – Optional layer mask, must have the same dimensions as height * width but can be a 1- or 2-dimensional array with row-major ordering (for a numpy 2D array this would mean with a shape of (height, width)

  • width (int) – Optional, width of the layer, does not have to be the same size as the document, limited to 30,000 for PSD files and 300,000 for PSB files. For group layers this is only relevant for the layer mask and can be left out otherwise

  • height (int) – Optional, height of the layer, does not have to be the same size as the document, limited to 30,000 for PSD files and 300,000 for PSB files. For group layers this is only relevant for the layer mask and can be left out otherwise

  • blend_mode (psapi.enum.BlendMode) – Optional, the blend mode of the layer, ‘Passthrough’ is the default for groups.

  • pos_x (int) – Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered. For group layers this is only relevant for the layer mask and can be left out otherwise

  • pos_y (int) – Optional, the relative offset of the layer to the center of the document, 0 indicates the layer is centered. For group layers this is only relevant for the layer mask and can be left out otherwise

  • opacity (int) – The opacity of the layer from 0-255 where 0 is 0% and 255 is 100%. Defaults to 255

  • compression (psapi.enum.Compression) – The compression to apply to all the channels of the layer, including mask channels

  • color_mode (psapi.enum.ColorMode) – The color mode of the Layer, this must be identical to the color mode of the document. Defaults to RGB

  • is_collapsed (bool) – Whether the group is collapsed (closed)

  • is_visible (bool) – Whether the group is visible

  • is_locked (bool) – Whether the group is locked

Raises:

ValueError: if length of layer name is greater than 255

ValueError: if size of layer mask is not width*height

ValueError: if width of layer is negative

ValueError: if height of layer is negative

ValueError: if opacity is not between 0-255

__getitem__(self: photoshopapi.lib64.photoshopapi.GroupLayer_8bit, value: str) photoshopapi.lib64.photoshopapi.Layer_8bit#

Get the specified layer from the group using dict-like indexing. This may be chained as deep as the layer hierarchy goes

group_layer: GroupLayer_*bit = # Our group layer instance
nested_img_layer = group_layer["NestedGroup"]["Image"]
Parameters:

value (str) – The name of the layer to search for

Raises:

KeyError: If the requested layer is not found

Returns:

The requested layer instance

add_layer(self: photoshopapi.lib64.photoshopapi.GroupLayer_8bit, layered_file: photoshopapi.lib64.photoshopapi.LayeredFile_8bit, layer: photoshopapi.lib64.photoshopapi.Layer_8bit) None#

Add the specified layer to the group

Parameters:
  • layered_file (psapi.LayeredFile_*bit) – The top level LayeredFile instance, required to ensure a layer doesnt get added twice

  • layer (Layer_*bit) – the layer instance to insert under the group

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.

remove_layer(*args, **kwargs)#

Overloaded function.

  1. remove_layer(self: photoshopapi.lib64.photoshopapi.GroupLayer_8bit, index: int) -> None

    Remove the specified layer from the group, raises a warning if the index isnt valid

    param index:

    The index of the layer to be removed

    type index:

    int

  2. remove_layer(self: photoshopapi.lib64.photoshopapi.GroupLayer_8bit, layer: photoshopapi.lib64.photoshopapi.Layer_8bit) -> None

    Remove the specified layer from the group, raises a warning if the layer isnt under the group

    param layer:

    The layer to be removed

    type layer:

    Layer_*bit

  3. remove_layer(self: photoshopapi.lib64.photoshopapi.GroupLayer_8bit, layer_name: str) -> None

    Remove the specified layer from the group, raises a warning if the layer isnt under the group

    param layer_name:

    The layer to be removed

    type layer_name:

    str

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.