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 psapi.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

layer_maskpsapi.LayerMask_*

The pixel mask applied to the layer

blend_modeenum.BlendMode

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

opacityint

The layers opacity from 0-255 with 255 being 100%

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

__init__(self: psapi.GroupLayer_8bit, layer_name: str, layer_mask: Optional[numpy.ndarray[numpy.uint8]] = None, width: int = 0, height: int = 0, blend_mode: psapi.enum.BlendMode = <BlendMode.passthrough: 0>, pos_x: int = 0, pos_y: int = 0, opacity: int = 255, compression: psapi.enum.Compression = <Compression.zipprediction: 3>, color_mode: psapi.enum.ColorMode = <ColorMode.rgb: 3>, is_collapsed: 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 or not the group is collapsed (closed)

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: psapi.GroupLayer_8bit, value: str) psapi.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: psapi.GroupLayer_8bit, layered_file: psapi.LayeredFile_8bit, layer: psapi.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

get_mask_data(self: psapi.Layer_8bit, do_copy: bool = True) numpy.ndarray[numpy.uint8]#

Get the pixel mask data associated with the layer (if it exists), if it doesnt a warning gets raised and a null-size numpy.ndarray is returned.

The size of the mask is not necessarily the same as the layer

Parameters:

do_copy (bool) – Whether or not to copy the image data on extraction, if False the mask channel is freed

Returns:

The extracted channel with dimensions (mask_height, mask_width)

Return type:

numpy.ndarray

remove_layer(*args, **kwargs)#

Overloaded function.

  1. remove_layer(self: psapi.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: psapi.GroupLayer_8bit, layer: psapi.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: psapi.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