psd_tools.api.adjustments¶
Adjustment and fill layers.
Example:
if layer.kind == 'brightnesscontrast':
print(layer.brightness)
if layer.kind == 'gradientfill':
print(layer.gradient_kind)
Fill layers¶
Fill layers are similar to ShapeLayer
except that the layer might not have an associated vector mask. The layer
therefore expands the entire canvas of the PSD document.
Fill layers all inherit from FillLayer
.
Example:
if isinstance(layer, psd_tools.layers.FillLayer):
image = layer.compose()
SolidColorFill¶
-
class
psd_tools.api.adjustments.
SolidColorFill
(*args)[source]¶ Solid color fill.
-
bbox
¶ (left, top, right, bottom) tuple.
-
blend_mode
¶ Blend mode of this layer. Writable.
Example:
from psd_tools.constants import BlendMode if layer.blend_mode == BlendMode.NORMAL: layer.blend_mode = BlendMode.SCREEN
Returns: BlendMode
.
-
bottom
¶ Bottom coordinate.
Returns: int
-
clip_layers
¶ Clip layers associated with this layer.
To compose clipping layers:
from psd_tools import compose clip_mask = compose(layer.clip_layers)
Returns: list of layers
-
clipping_layer
¶ Clipping flag for this layer. Writable.
Returns: bool
-
compose
(force=False, bbox=None, layer_filter=None)¶ Deprecated, use
composite()
.Compose layer and masks (mask, vector mask, and clipping layers).
Note that the resulting image size is not necessarily equal to the layer size due to different mask dimensions. The offset of the composed image is stored at .info[‘offset’] attribute of PIL.Image.
Parameters: bbox – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Returns: PIL.Image
, or None if the layer has no pixel.
-
composite
(viewport=None, force=False, color=1.0, alpha=0.0, layer_filter=None, apply_icc=False)¶ Composite layer and masks (mask, vector mask, and clipping layers).
Parameters: - viewport – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Default is the layer’s bbox.
- force – Boolean flag to force vector drawing.
- color – Backdrop color specified by scalar or tuple of scalar. The color value should be in [0.0, 1.0]. For example, (1., 0., 0.) specifies red in RGB color mode.
- alpha – Backdrop alpha in [0.0, 1.0].
- layer_filter – Callable that takes a layer as argument and
returns whether if the layer is composited. Default is
is_visible()
.
Returns: PIL.Image
.
-
data
¶ Color in Descriptor(RGB).
-
has_clip_layers
()¶ Returns True if the layer has associated clipping.
Returns: bool
-
has_effects
()¶ Returns True if the layer has effects.
Returns: bool
-
has_mask
()¶ Returns True if the layer has a mask.
Returns: bool
-
has_origination
()¶ Returns True if the layer has live shape properties.
Returns: bool
-
has_pixels
()¶ Returns True if the layer has associated pixels. When this is True, topil method returns
PIL.Image
.Returns: bool
-
has_stroke
()¶ Returns True if the shape has a stroke.
-
has_vector_mask
()¶ Returns True if the layer has a vector mask.
Returns: bool
-
height
¶ Height of the layer.
Returns: int
-
is_group
()¶ Return True if the layer is a group.
Returns: bool
-
is_visible
()¶ Layer visibility. Takes group visibility in account.
Returns: bool
-
kind
¶ Kind of this layer, such as group, pixel, shape, type, smartobject, or psdimage. Class name without layer suffix.
Returns: str
-
layer_id
¶ Layer ID.
Returns: int layer id. if the layer is not assigned an id, -1.
-
left
¶ Left coordinate. Writable.
Returns: int
-
name
¶ Layer name. Writable.
Returns: str
-
numpy
(channel=None, real_mask=True)¶ Get NumPy array of the layer.
Parameters: channel – Which channel to return, can be ‘color’, ‘shape’, ‘alpha’, or ‘mask’. Default is ‘color+alpha’. Returns: numpy.ndarray
or None if there is no pixel.
-
offset
¶ (left, top) tuple. Writable.
Returns: tuple
-
opacity
¶ Opacity of this layer in [0, 255] range. Writable.
Returns: int
-
origination
¶ Property for a list of live shapes or a line.
Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.
See
psd_tools.api.shape
.Returns: List of Invalidated
,Rectangle
,RoundedRectangle
,Ellipse
, orLine
.
-
parent
¶ Parent of this layer.
-
right
¶ Right coordinate.
Returns: int
-
size
¶ (width, height) tuple.
Returns: tuple
-
stroke
¶ Property for strokes.
-
tagged_blocks
¶ Layer tagged blocks that is a dict-like container of settings.
See
psd_tools.constants.Tag
for available keys.Returns: TaggedBlocks
or None.Example:
from psd_tools.constants import Tag metadata = layer.tagged_blocks.get_data(Tag.METADATA_SETTING)
-
top
¶ Top coordinate. Writable.
Returns: int
-
topil
(channel=None, apply_icc=False)¶ Get PIL Image of the layer.
Parameters: - channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB
image. See
ChannelID
. When None, the method returns all the channels supported by PIL modes. - apply_icc – Whether to apply ICC profile conversion to sRGB.
Returns: PIL.Image
, or None if the layer has no pixels.Example:
from psd_tools.constants import ChannelID image = layer.topil() red = layer.topil(ChannelID.CHANNEL_0) alpha = layer.topil(ChannelID.TRANSPARENCY_MASK)
Note
Not all of the PSD image modes are supported in
PIL.Image
. For example, ‘CMYK’ mode cannot include alpha channel in PIL. In this case, topil drops alpha channel.- channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB
image. See
-
vector_mask
¶ Returns vector mask associated with this layer.
Returns: VectorMask
or None
-
visible
¶ Layer visibility. Doesn’t take group visibility in account. Writable.
Returns: bool
-
width
¶ Width of the layer.
Returns: int
-
PatternFill¶
-
class
psd_tools.api.adjustments.
PatternFill
(*args)[source]¶ Pattern fill.
-
bbox
¶ (left, top, right, bottom) tuple.
-
blend_mode
¶ Blend mode of this layer. Writable.
Example:
from psd_tools.constants import BlendMode if layer.blend_mode == BlendMode.NORMAL: layer.blend_mode = BlendMode.SCREEN
Returns: BlendMode
.
-
bottom
¶ Bottom coordinate.
Returns: int
-
clip_layers
¶ Clip layers associated with this layer.
To compose clipping layers:
from psd_tools import compose clip_mask = compose(layer.clip_layers)
Returns: list of layers
-
clipping_layer
¶ Clipping flag for this layer. Writable.
Returns: bool
-
compose
(force=False, bbox=None, layer_filter=None)¶ Deprecated, use
composite()
.Compose layer and masks (mask, vector mask, and clipping layers).
Note that the resulting image size is not necessarily equal to the layer size due to different mask dimensions. The offset of the composed image is stored at .info[‘offset’] attribute of PIL.Image.
Parameters: bbox – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Returns: PIL.Image
, or None if the layer has no pixel.
-
composite
(viewport=None, force=False, color=1.0, alpha=0.0, layer_filter=None, apply_icc=False)¶ Composite layer and masks (mask, vector mask, and clipping layers).
Parameters: - viewport – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Default is the layer’s bbox.
- force – Boolean flag to force vector drawing.
- color – Backdrop color specified by scalar or tuple of scalar. The color value should be in [0.0, 1.0]. For example, (1., 0., 0.) specifies red in RGB color mode.
- alpha – Backdrop alpha in [0.0, 1.0].
- layer_filter – Callable that takes a layer as argument and
returns whether if the layer is composited. Default is
is_visible()
.
Returns: PIL.Image
.
-
data
¶ Pattern in Descriptor(PATTERN).
-
has_clip_layers
()¶ Returns True if the layer has associated clipping.
Returns: bool
-
has_effects
()¶ Returns True if the layer has effects.
Returns: bool
-
has_mask
()¶ Returns True if the layer has a mask.
Returns: bool
-
has_origination
()¶ Returns True if the layer has live shape properties.
Returns: bool
-
has_pixels
()¶ Returns True if the layer has associated pixels. When this is True, topil method returns
PIL.Image
.Returns: bool
-
has_stroke
()¶ Returns True if the shape has a stroke.
-
has_vector_mask
()¶ Returns True if the layer has a vector mask.
Returns: bool
-
height
¶ Height of the layer.
Returns: int
-
is_group
()¶ Return True if the layer is a group.
Returns: bool
-
is_visible
()¶ Layer visibility. Takes group visibility in account.
Returns: bool
-
kind
¶ Kind of this layer, such as group, pixel, shape, type, smartobject, or psdimage. Class name without layer suffix.
Returns: str
-
layer_id
¶ Layer ID.
Returns: int layer id. if the layer is not assigned an id, -1.
-
left
¶ Left coordinate. Writable.
Returns: int
-
name
¶ Layer name. Writable.
Returns: str
-
numpy
(channel=None, real_mask=True)¶ Get NumPy array of the layer.
Parameters: channel – Which channel to return, can be ‘color’, ‘shape’, ‘alpha’, or ‘mask’. Default is ‘color+alpha’. Returns: numpy.ndarray
or None if there is no pixel.
-
offset
¶ (left, top) tuple. Writable.
Returns: tuple
-
opacity
¶ Opacity of this layer in [0, 255] range. Writable.
Returns: int
-
origination
¶ Property for a list of live shapes or a line.
Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.
See
psd_tools.api.shape
.Returns: List of Invalidated
,Rectangle
,RoundedRectangle
,Ellipse
, orLine
.
-
parent
¶ Parent of this layer.
-
right
¶ Right coordinate.
Returns: int
-
size
¶ (width, height) tuple.
Returns: tuple
-
stroke
¶ Property for strokes.
-
tagged_blocks
¶ Layer tagged blocks that is a dict-like container of settings.
See
psd_tools.constants.Tag
for available keys.Returns: TaggedBlocks
or None.Example:
from psd_tools.constants import Tag metadata = layer.tagged_blocks.get_data(Tag.METADATA_SETTING)
-
top
¶ Top coordinate. Writable.
Returns: int
-
topil
(channel=None, apply_icc=False)¶ Get PIL Image of the layer.
Parameters: - channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB
image. See
ChannelID
. When None, the method returns all the channels supported by PIL modes. - apply_icc – Whether to apply ICC profile conversion to sRGB.
Returns: PIL.Image
, or None if the layer has no pixels.Example:
from psd_tools.constants import ChannelID image = layer.topil() red = layer.topil(ChannelID.CHANNEL_0) alpha = layer.topil(ChannelID.TRANSPARENCY_MASK)
Note
Not all of the PSD image modes are supported in
PIL.Image
. For example, ‘CMYK’ mode cannot include alpha channel in PIL. In this case, topil drops alpha channel.- channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB
image. See
-
vector_mask
¶ Returns vector mask associated with this layer.
Returns: VectorMask
or None
-
visible
¶ Layer visibility. Doesn’t take group visibility in account. Writable.
Returns: bool
-
width
¶ Width of the layer.
Returns: int
-
GradientFill¶
-
class
psd_tools.api.adjustments.
GradientFill
(*args)[source]¶ Gradient fill.
-
bbox
¶ (left, top, right, bottom) tuple.
-
blend_mode
¶ Blend mode of this layer. Writable.
Example:
from psd_tools.constants import BlendMode if layer.blend_mode == BlendMode.NORMAL: layer.blend_mode = BlendMode.SCREEN
Returns: BlendMode
.
-
bottom
¶ Bottom coordinate.
Returns: int
-
clip_layers
¶ Clip layers associated with this layer.
To compose clipping layers:
from psd_tools import compose clip_mask = compose(layer.clip_layers)
Returns: list of layers
-
clipping_layer
¶ Clipping flag for this layer. Writable.
Returns: bool
-
compose
(force=False, bbox=None, layer_filter=None)¶ Deprecated, use
composite()
.Compose layer and masks (mask, vector mask, and clipping layers).
Note that the resulting image size is not necessarily equal to the layer size due to different mask dimensions. The offset of the composed image is stored at .info[‘offset’] attribute of PIL.Image.
Parameters: bbox – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Returns: PIL.Image
, or None if the layer has no pixel.
-
composite
(viewport=None, force=False, color=1.0, alpha=0.0, layer_filter=None, apply_icc=False)¶ Composite layer and masks (mask, vector mask, and clipping layers).
Parameters: - viewport – Viewport bounding box specified by (x1, y1, x2, y2) tuple. Default is the layer’s bbox.
- force – Boolean flag to force vector drawing.
- color – Backdrop color specified by scalar or tuple of scalar. The color value should be in [0.0, 1.0]. For example, (1., 0., 0.) specifies red in RGB color mode.
- alpha – Backdrop alpha in [0.0, 1.0].
- layer_filter – Callable that takes a layer as argument and
returns whether if the layer is composited. Default is
is_visible()
.
Returns: PIL.Image
.
-
data
¶ Gradient in Descriptor(GRADIENT).
-
gradient_kind
¶ Kind of the gradient, one of the following:
- Linear
- Radial
- Angle
- Reflected
- Diamond
-
has_clip_layers
()¶ Returns True if the layer has associated clipping.
Returns: bool
-
has_effects
()¶ Returns True if the layer has effects.
Returns: bool
-
has_mask
()¶ Returns True if the layer has a mask.
Returns: bool
-
has_origination
()¶ Returns True if the layer has live shape properties.
Returns: bool
-
has_pixels
()¶ Returns True if the layer has associated pixels. When this is True, topil method returns
PIL.Image
.Returns: bool
-
has_stroke
()¶ Returns True if the shape has a stroke.
-
has_vector_mask
()¶ Returns True if the layer has a vector mask.
Returns: bool
-
height
¶ Height of the layer.
Returns: int
-
is_group
()¶ Return True if the layer is a group.
Returns: bool
-
is_visible
()¶ Layer visibility. Takes group visibility in account.
Returns: bool
-
kind
¶ Kind of this layer, such as group, pixel, shape, type, smartobject, or psdimage. Class name without layer suffix.
Returns: str
-
layer_id
¶ Layer ID.
Returns: int layer id. if the layer is not assigned an id, -1.
-
left
¶ Left coordinate. Writable.
Returns: int
-
name
¶ Layer name. Writable.
Returns: str
-
numpy
(channel=None, real_mask=True)¶ Get NumPy array of the layer.
Parameters: channel – Which channel to return, can be ‘color’, ‘shape’, ‘alpha’, or ‘mask’. Default is ‘color+alpha’. Returns: numpy.ndarray
or None if there is no pixel.
-
offset
¶ (left, top) tuple. Writable.
Returns: tuple
-
opacity
¶ Opacity of this layer in [0, 255] range. Writable.
Returns: int
-
origination
¶ Property for a list of live shapes or a line.
Some of the vector masks have associated live shape properties, that are Photoshop feature to handle primitive shapes such as a rectangle, an ellipse, or a line. Vector masks without live shape properties are plain path objects.
See
psd_tools.api.shape
.Returns: List of Invalidated
,Rectangle
,RoundedRectangle
,Ellipse
, orLine
.
-
parent
¶ Parent of this layer.
-
right
¶ Right coordinate.
Returns: int
-
size
¶ (width, height) tuple.
Returns: tuple
-
stroke
¶ Property for strokes.
-
tagged_blocks
¶ Layer tagged blocks that is a dict-like container of settings.
See
psd_tools.constants.Tag
for available keys.Returns: TaggedBlocks
or None.Example:
from psd_tools.constants import Tag metadata = layer.tagged_blocks.get_data(Tag.METADATA_SETTING)
-
top
¶ Top coordinate. Writable.
Returns: int
-
topil
(channel=None, apply_icc=False)¶ Get PIL Image of the layer.
Parameters: - channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB
image. See
ChannelID
. When None, the method returns all the channels supported by PIL modes. - apply_icc – Whether to apply ICC profile conversion to sRGB.
Returns: PIL.Image
, or None if the layer has no pixels.Example:
from psd_tools.constants import ChannelID image = layer.topil() red = layer.topil(ChannelID.CHANNEL_0) alpha = layer.topil(ChannelID.TRANSPARENCY_MASK)
Note
Not all of the PSD image modes are supported in
PIL.Image
. For example, ‘CMYK’ mode cannot include alpha channel in PIL. In this case, topil drops alpha channel.- channel – Which channel to return; e.g., 0 for ‘R’ channel in RGB
image. See
-
vector_mask
¶ Returns vector mask associated with this layer.
Returns: VectorMask
or None
-
visible
¶ Layer visibility. Doesn’t take group visibility in account. Writable.
Returns: bool
-
width
¶ Width of the layer.
Returns: int
-
Adjustment layers¶
Adjustment layers apply image filtering to the composed result. All adjustment
layers inherit from
AdjustmentLayer
. Adjustment layers do not
have pixels, and currently ignored in compose. Attempts to call topil
on adjustment layers always return None.
Just as any other layer, adjustment layers might have an associated mask or vector mask. Adjustment can appear in other layers’ clipping layers.
Example:
if isinstance(layer, psd_tools.layers.AdjustmentLayer):
print(layer.kind)
BrightnessContrast¶
Curves¶
Exposure¶
Levels¶
Vibrance¶
HueSaturation¶
-
class
psd_tools.api.adjustments.
HueSaturation
(*args)[source]¶ Hue/Saturation adjustment.
HueSaturation contains a list of data.
-
colorization
¶ Colorization.
Returns: tuple
-
data
¶ List of Hue/Saturation records.
Returns: list
-
enable_colorization
¶ Enable colorization.
Returns: int
-
master
¶ Master record.
Returns: tuple
-
ColorBalance¶
BlackAndWhite¶
PhotoFilter¶
ChannelMixer¶
Posterize¶
Threshold¶
SelectiveColor¶
GradientMap¶
-
class
psd_tools.api.adjustments.
GradientMap
(*args)[source]¶ Gradient map adjustment.
-
color_model
¶
-
color_stops
¶
-
dithered
¶
-
expansion
¶
-
gradient_name
¶
-
interpolation
¶ Interpolation between 0.0 and 1.0.
-
length
¶
-
max_color
¶
-
min_color
¶
-
mode
¶
-
random_seed
¶
-
reversed
¶
-
roughness
¶
-
show_transparency
¶
-
transparency_stops
¶
-
use_vector_color
¶
-