psd_tools.api.shape¶
Shape module.
In PSD/PSB, shapes are all represented as VectorMask
in each
layer, and optionally there might be Origination
object to control
live shape properties and Stroke
to specify how outline is
stylized.
VectorMask¶
- class psd_tools.api.shape.VectorMask(data)[source]¶
Vector mask data.
Vector mask is a resolution-independent mask that consists of one or more Path objects. In Photoshop, all the path objects are represented as Bezier curves. Check
paths
property for how to deal with path objects.- property bbox¶
Bounding box tuple (left, top, right, bottom) in relative coordinates, where top-left corner is (0., 0.) and bottom-right corner is (1., 1.).
- Returns:
tuple
- property clipboard_record¶
Clipboard record containing bounding box information.
Depending on the Photoshop version, this field can be None.
- property disabled¶
If the mask is disabled.
- property initial_fill_rule¶
Initial fill rule.
When 0, fill inside of the path. When 1, fill outside of the shape.
- Returns:
int
- property inverted¶
Invert the mask.
- property not_linked¶
If the knots are not linked.
- property paths¶
List of
Subpath
. Subpath is a list-like structure that contains one or moreKnot
items. Knot contains relative coordinates of control points for a Bezier curve.index
indicates which origination item the subpath belongs, andoperation
indicates how to combine multiple shape paths.In PSD, path fill rule is even-odd.
Example:
for subpath in layer.vector_mask.paths: anchors = [( int(knot.anchor[1] * psd.width), int(knot.anchor[0] * psd.height), ) for knot in subpath]
- Returns:
List of Subpath.
Stroke¶
- class psd_tools.api.shape.Stroke(data)[source]¶
Stroke contains decorative information for strokes.
This is a thin wrapper around
Descriptor
structure. Check _data attribute to get the raw data.- property blend_mode¶
Blend mode.
- property content¶
Fill effect.
- property enabled¶
If the stroke is enabled.
- property fill_enabled¶
If the stroke fill is enabled.
- property line_alignment¶
Alignment, one of inner, outer, center.
- property line_cap_type¶
Cap type, one of butt, round, square.
- property line_dash_offset¶
Line dash offset in float.
- Returns:
float
- property line_dash_set¶
Line dash set in list of
UnitFloat
.- Returns:
list
- property line_join_type¶
Join type, one of miter, round, bevel.
- property line_width¶
Stroke width in float.
- property miter_limit¶
Miter limit in float.
- property opacity¶
Opacity value.
- property stroke_adjust¶
Stroke adjust
Origination¶
Origination keeps live shape properties for some of the primitive shapes.
Origination objects are accessible via
origination
property of layers.
Following primitive shapes are
defined: Invalidated
,
Line
,
Rectangle
,
Ellipse
,
and RoundedRectangle
.
Invalidated¶
- class psd_tools.api.shape.Invalidated(data)[source]¶
Invalidated live shape.
This equals to a primitive shape that does not provide Live shape properties. Use
VectorMask
to access shape information instead of this origination object.- property invalidated¶
- Returns:
bool
Line¶
- class psd_tools.api.shape.Line(data)[source]¶
Line live shape.
- property arrow_conc¶
- Returns:
int
- property arrow_end¶
Line arrow end.
- Returns:
bool
- property arrow_length¶
Line arrow length.
- Returns:
float
- property arrow_start¶
Line arrow start.
- Returns:
bool
- property arrow_width¶
Line arrow width.
- Returns:
float
- property bbox¶
Bounding box of the live shape.
- Returns:
- property index¶
Origination item index.
- Returns:
int
- property invalidated¶
- Returns:
bool
- property line_end¶
Line end.
- Returns:
- property line_start¶
Line start.
- Returns:
- property line_weight¶
Line weight
- Returns:
float
- property resolution¶
Resolution.
- Returns:
float
Ellipse¶
- class psd_tools.api.shape.Ellipse(data)[source]¶
Ellipse live shape.
- property bbox¶
Bounding box of the live shape.
- Returns:
- property index¶
Origination item index.
- Returns:
int
- property invalidated¶
- Returns:
bool
- property resolution¶
Resolution.
- Returns:
float
Rectangle¶
- class psd_tools.api.shape.Rectangle(data)[source]¶
Rectangle live shape.
- property bbox¶
Bounding box of the live shape.
- Returns:
- property index¶
Origination item index.
- Returns:
int
- property invalidated¶
- Returns:
bool
- property resolution¶
Resolution.
- Returns:
float
RoundedRectangle¶
- class psd_tools.api.shape.RoundedRectangle(data)[source]¶
Rounded rectangle live shape.
- property bbox¶
Bounding box of the live shape.
- Returns:
- property index¶
Origination item index.
- Returns:
int
- property invalidated¶
- Returns:
bool
- property radii¶
Corner radii of rounded rectangles. The order is top-left, top-right, bottom-left, bottom-right.
- Returns:
- property resolution¶
Resolution.
- Returns:
float