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: VectorMaskSetting)[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
pathsproperty for how to deal with path objects.- property bbox: tuple[float, float, float, float]
Bounding box tuple (left, top, right, bottom) in relative coordinates, where top-left corner is (0., 0.) and bottom-right corner is (1., 1.).
The bounding box accounts for the full extent of all cubic Bezier curves, not just the anchor points.
- Returns:
tuple
- property clipboard_record: ClipboardRecord | None
Clipboard record containing bounding box information.
Depending on the Photoshop version, this field can be None.
- property disabled: bool
If the mask is disabled.
- property initial_fill_rule: int
Initial fill rule.
When 0, fill inside of the path. When 1, fill outside of the shape.
- Returns:
int
- property inverted: bool
Invert the mask.
- property not_linked: bool
If the knots are not linked.
- property paths: list[Subpath]
List of
Subpath. Subpath is a list-like structure that contains one or moreKnotitems. Knot contains relative coordinates of control points for a Bezier curve.indexindicates which origination item the subpath belongs, andoperationindicates 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: VectorStrokeContentSetting)[source]
Stroke contains decorative information for strokes.
This is a thin wrapper around
Descriptorstructure. Check _data attribute to get the raw data.- property blend_mode: Any
Blend mode.
- property content: Any
Fill effect.
- property enabled: bool
If the stroke is enabled.
- property fill_enabled: bool
If the stroke fill is enabled.
- property line_alignment: str
Alignment, one of inner, outer, center.
- property line_cap_type: str
Cap type, one of butt, round, square.
- property line_dash_offset: float
Line dash offset in float.
- Returns:
float
- property line_dash_set: list
Line dash set in list of
UnitFloat.- Returns:
list
- property line_join_type: str
Join type, one of miter, round, bevel.
- property line_width: float
Stroke width in float.
- property miter_limit: Any
Miter limit in float.
- property opacity: Any
Opacity value.
- property stroke_adjust: Any
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: Descriptor)[source]
Invalidated live shape.
This equals to a primitive shape that does not provide Live shape properties. Use
VectorMaskto access shape information instead of this origination object.- property invalidated: bool
bool
- Type:
return
Line
- class psd_tools.api.shape.Line(data: Descriptor)[source]
Line live shape.
- property arrow_conc: int
int
- Type:
return
- property arrow_end: bool
Line arrow end.
- Returns:
bool
- property arrow_length: float
Line arrow length.
- Returns:
float
- property arrow_start: bool
Line arrow start.
- Returns:
bool
- property arrow_width: float
Line arrow width.
- Returns:
float
- property bbox: tuple[float, float, float, float]
Bounding box of the live shape.
- Returns:
- property index: int
Origination item index.
- Returns:
int
- property invalidated: bool
bool
- Type:
return
- property line_end: Descriptor
Line end.
- Returns:
- property line_start: Descriptor
Line start.
- Returns:
- property line_weight: float
Line weight
- Returns:
float
- property resolution: float
Resolution.
- Returns:
float
Ellipse
- class psd_tools.api.shape.Ellipse(data: Descriptor)[source]
Ellipse live shape.
- property bbox: tuple[float, float, float, float]
Bounding box of the live shape.
- Returns:
- property index: int
Origination item index.
- Returns:
int
- property invalidated: bool
bool
- Type:
return
- property resolution: float
Resolution.
- Returns:
float
Rectangle
- class psd_tools.api.shape.Rectangle(data: Descriptor)[source]
Rectangle live shape.
- property bbox: tuple[float, float, float, float]
Bounding box of the live shape.
- Returns:
- property index: int
Origination item index.
- Returns:
int
- property invalidated: bool
bool
- Type:
return
- property resolution: float
Resolution.
- Returns:
float
RoundedRectangle
- class psd_tools.api.shape.RoundedRectangle(data: Descriptor)[source]
Rounded rectangle live shape.
- property bbox: tuple[float, float, float, float]
Bounding box of the live shape.
- Returns:
- property index: int
Origination item index.
- Returns:
int
- property invalidated: bool
bool
- Type:
return
- property radii: Any
Corner radii of rounded rectangles. The order is top-left, top-right, bottom-left, bottom-right.
- Returns:
- property resolution: float
Resolution.
- Returns:
float