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.

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
clipboard_record

Clipboard record containing bounding box information.

Depending on the Photoshop version, this field can be None.

disabled

If the mask is disabled.

initial_fill_rule

Initial fill rule.

When 0, fill inside of the path. When 1, fill outside of the shape.

Returns:int
inverted

Invert the mask.

not_linked

If the knots are not linked.

paths

List of Subpath. Subpath is a list-like structure that contains one or more Knot items. Knot contains relative coordinates of control points for a Bezier curve. index indicates which origination item the subpath belongs, and operation 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.

blend_mode

Blend mode.

content

Fill effect.

enabled

If the stroke is enabled.

fill_enabled

If the stroke fill is enabled.

line_alignment

Alignment, one of inner, outer, center.

line_cap_type

Cap type, one of butt, round, square.

line_dash_offset

Line dash offset in float.

Returns:float
line_dash_set

Line dash set in list of UnitFloat.

Returns:list
line_join_type

Join type, one of miter, round, bevel.

line_width

Stroke width in float.

miter_limit

Miter limit in float.

opacity

Opacity value.

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.

invalidated
Returns:bool

Line

class psd_tools.api.shape.Line(data)[source]

Line live shape.

arrow_conc
Returns:int
arrow_end

Line arrow end.

Returns:bool
arrow_length

Line arrow length.

Returns:float
arrow_start

Line arrow start.

Returns:bool
arrow_width

Line arrow width.

Returns:float
bbox

Bounding box of the live shape.

Returns:Descriptor
index

Origination item index.

Returns:int
invalidated
Returns:bool
line_end

Line end.

Returns:Descriptor
line_start

Line start.

Returns:Descriptor
line_weight

Line weight

Returns:float
origin_type

Type of the vector shape.

Returns:int
resolution

Resolution.

Returns:float

Ellipse

class psd_tools.api.shape.Ellipse(data)[source]

Ellipse live shape.

bbox

Bounding box of the live shape.

Returns:Descriptor
index

Origination item index.

Returns:int
invalidated
Returns:bool
origin_type

Type of the vector shape.

Returns:int
resolution

Resolution.

Returns:float

Rectangle

class psd_tools.api.shape.Rectangle(data)[source]

Rectangle live shape.

bbox

Bounding box of the live shape.

Returns:Descriptor
index

Origination item index.

Returns:int
invalidated
Returns:bool
origin_type

Type of the vector shape.

Returns:int
resolution

Resolution.

Returns:float

RoundedRectangle

class psd_tools.api.shape.RoundedRectangle(data)[source]

Rounded rectangle live shape.

bbox

Bounding box of the live shape.

Returns:Descriptor
index

Origination item index.

Returns:int
invalidated
Returns:bool
origin_type

Type of the vector shape.

Returns:int
radii

Corner radii of rounded rectangles. The order is top-left, top-right, bottom-left, bottom-right.

Returns:Descriptor
resolution

Resolution.

Returns:float