pytoshop.user.nested_layers¶
Convert a PSD file to/from nested layers.
-
class
pytoshop.user.nested_layers.Group(name='', visible=True, opacity=255, group_id=0, blend_mode=<BlendMode.pass_through: b'pass'>, layers=None, closed=True, metadata=None, layer_color=0)[source]¶ Bases:
pytoshop.user.nested_layers.LayerA
Layerthat may contain otherLayerinstances.-
closed¶ Is layer closed in GUI?
-
layers¶ List of sublayers
-
-
class
pytoshop.user.nested_layers.Image(name='', visible=True, opacity=255, group_id=0, blend_mode=<BlendMode.normal: b'norm'>, top=0, left=0, bottom=None, right=None, channels=None, metadata=None, layer_color=0, color_mode=None)[source]¶ Bases:
pytoshop.user.nested_layers.LayerA
Layercontaining image data, i.e. a leaf node.-
bottom¶ The bottom of the layer, in pixels. If not provided, will be automatically determined from channel data.
-
channels¶ The channel image data. May be one of the following –
- A dictionary from
enums.ChannelIdto 2-D numpy arrays. - A 3-D numpy array of the shape (num_channels, height, width)
- A list of numpy arrays where each is a channel.
It is better to use
get_channelandset_channelto- A dictionary from
-
color_mode¶ The color mode of the image.
-
get_channel(color)[source]¶ Get a channel for a given color. Raises an error if the color space doesn’t have the given color.
Parameters: color (enums.ColorChannel) – Returns: channel Return type: 2-D numpy array
-
left¶ The left of the layer, in pixels.
-
right¶ The right of the layer, in pixels. If not provided, will be automatically determined from channel data.
-
set_channel(color, channel)[source]¶ Get a channel for a given color. Raises an error if the color space doesn’t have the given color.
Parameters: - color (enums.ColorChannel) –
- channel (2-D numpy array) –
-
top¶ The top of the layer, in pixels.
-
-
class
pytoshop.user.nested_layers.Layer[source]¶ Bases:
objectBase class of all layers.
-
blend_mode¶ blend mode
-
group_id¶ Linked layer id
-
layer_color¶ layer color (as it appears in the layer list)
-
metadata¶
-
name¶ The name of the layer
-
opacity¶ Opacity. 0=transparent, 255=opaque
-
visible¶ Is layer visible?
-
-
pytoshop.user.nested_layers.nested_layers_to_psd(layers, color_mode, version=<Version.version_1: 1>, compression=<Compression.rle: 1>, depth=None, size=None, vector_mask=False)[source]¶ Convert a hierarchy of nested
Layerinstances to aPsdFile.Parameters: - layers (list of
Layerinstances) – The hierarchy of layers we want to create. - color_mode (
enums.ColorMode) – The color mode of the resulting PSD file (as well as the input image data). - version (
enums.Version, optional) – The version of the PSD spec to follow. - compression (
enums.Compression, optional) – The method of image compression to use for the layer image data. - depth (
enums.ColorDepth, optional) – The color depth of the resulting image. Must match the color depth of the data passed in. If not provided, the color depth will be automatically determined from the passed-in data. - size (2-tuple of int, optional) – The shape in the form
(height, width)of the resulting PSD file. If not provided, the height and width will be set to include all passed in layers, and the layers themselves will be adjusted so that none fall outside of the image. - vector_mask (bool, optional) – When
True, the mask for the layer will be a vector rectangle. This results in much smaller file sizes, but is not quite as accurately rendered by Photoshop. WhenFalse, a raster mask is used.
Returns: psdfile – The resulting PSD file.
Return type: - layers (list of