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 psapi.Layer_8bit#
Base type that all layers inherit from, this class should not be instantiated and instead the derivatives such as
psapi.GroupLayer_8bit
orpsapi.ImageLayer_8bit
should be used (with the appropriate bit depth).- Attributes:
- namestr
The name of the layer, cannot be longer than 255
- layer_masknp.ndarray
The pixel mask applied to the layer, read only
- 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
- 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