Skip to content

Functions

src.helpers.bounds.get_dimensions_from_bounds(bounds: LayerBounds) -> type[LayerDimensions]

Compute width and height based on a set of bounds given.

Parameters:

Name Type Description Default
bounds LayerBounds

List of bounds given.

required

Returns:

Type Description
type[LayerDimensions]

Dict containing height, width, and positioning locations.

Source code in src\helpers\bounds.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def get_dimensions_from_bounds(bounds: LayerBounds) -> type[LayerDimensions]:
    """Compute width and height based on a set of bounds given.

    Args:
        bounds: List of bounds given.

    Returns:
        Dict containing height, width, and positioning locations.
    """
    width = int(bounds[2]-bounds[0])
    height = int(bounds[3]-bounds[1])
    return LayerDimensions(
        width=width,
        height=height,
        center_x=round((width / 2) + bounds[0]),
        center_y=round((height / 2) + bounds[1]),
        left=int(bounds[0]), right=int(bounds[2]),
        top=int(bounds[1]), bottom=int(bounds[3]))

src.helpers.bounds.get_layer_dimensions(layer: Union[ArtLayer, LayerSet]) -> type[LayerDimensions]

Compute the width and height dimensions of a layer.

Parameters:

Name Type Description Default
layer ArtLayer | LayerSet

A layer object

required

Returns:

Type Description
type[LayerDimensions]

Dict containing height, width, and positioning locations.

Source code in src\helpers\bounds.py
74
75
76
77
78
79
80
81
82
83
def get_layer_dimensions(layer: Union[ArtLayer, LayerSet]) -> type[LayerDimensions]:
    """Compute the width and height dimensions of a layer.

    Args:
        layer: A layer object

    Returns:
        Dict containing height, width, and positioning locations.
    """
    return get_dimensions_from_bounds(layer.bounds)

src.helpers.bounds.get_layer_width(layer: Union[ArtLayer, LayerSet]) -> Union[float, int]

Returns the width of a given layer.

Parameters:

Name Type Description Default
layer ArtLayer | LayerSet

A layer object

required

Returns:

Name Type Description
int float | int

Width of the layer in pixels.

Source code in src\helpers\bounds.py
86
87
88
89
90
91
92
93
94
95
96
def get_layer_width(layer: Union[ArtLayer, LayerSet]) -> Union[float, int]:
    """Returns the width of a given layer.

    Args:
        layer: A layer object

    Returns:
        int: Width of the layer in pixels.
    """
    bounds = layer.bounds
    return int(bounds[2]-bounds[0])

src.helpers.bounds.get_layer_height(layer: Union[ArtLayer, LayerSet]) -> Union[float, int]

Returns the height of a given layer.

Parameters:

Name Type Description Default
layer ArtLayer | LayerSet

A layer object

required

Returns:

Name Type Description
int float | int

Height of the layer in pixels.

Source code in src\helpers\bounds.py
 99
100
101
102
103
104
105
106
107
108
109
def get_layer_height(layer: Union[ArtLayer, LayerSet]) -> Union[float, int]:
    """Returns the height of a given layer.

    Args:
        layer: A layer object

    Returns:
        int: Height of the layer in pixels.
    """
    bounds = layer.bounds
    return int(bounds[3]-bounds[1])

src.helpers.bounds.get_bounds_no_effects(layer: Union[ArtLayer, LayerSet]) -> LayerBounds

Returns the bounds of a given layer without its effects applied.

Parameters:

Name Type Description Default
layer ArtLayer | LayerSet

A layer object

required

Returns:

Name Type Description
list LayerBounds

Pixel location top left, top right, bottom left, bottom right.

Source code in src\helpers\bounds.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
def get_bounds_no_effects(layer: Union[ArtLayer, LayerSet]) -> LayerBounds:
    """Returns the bounds of a given layer without its effects applied.

    Args:
        layer: A layer object

    Returns:
        list: Pixel location top left, top right, bottom left, bottom right.
    """
    with suppress(Exception):
        d = get_layer_action_ref(layer)
        try:
            # Try getting bounds no effects
            bounds = d.getObjectValue(sID('boundsNoEffects'))
        except PS_EXCEPTIONS:
            # Try getting bounds
            bounds = d.getObjectValue(sID('bounds'))
        return (
            bounds.getInteger(sID('left')),
            bounds.getInteger(sID('top')),
            bounds.getInteger(sID('right')),
            bounds.getInteger(sID('bottom')))
    # Fallback to layer object bounds property
    return layer.bounds

src.helpers.bounds.get_dimensions_no_effects(layer: Union[ArtLayer, LayerSet]) -> type[LayerDimensions]

Compute the dimensions of a layer without its effects applied.

Parameters:

Name Type Description Default
layer ArtLayer | LayerSet

A layer object

required

Returns:

Type Description
type[LayerDimensions]

Dict containing height, width, and positioning locations.

Source code in src\helpers\bounds.py
143
144
145
146
147
148
149
150
151
152
153
def get_dimensions_no_effects(layer: Union[ArtLayer, LayerSet]) -> type[LayerDimensions]:
    """Compute the dimensions of a layer without its effects applied.

    Args:
        layer: A layer object

    Returns:
        Dict containing height, width, and positioning locations.
    """
    bounds = get_bounds_no_effects(layer)
    return get_dimensions_from_bounds(bounds)

src.helpers.bounds.get_width_no_effects(layer: Union[ArtLayer, LayerSet]) -> int

Returns the width of a given layer without its effects applied.

Parameters:

Name Type Description Default
layer ArtLayer | LayerSet

A layer object

required

Returns:

Name Type Description
int int

Width of the layer in pixels.

Source code in src\helpers\bounds.py
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def get_width_no_effects(layer: Union[ArtLayer, LayerSet]) -> int:
    """Returns the width of a given layer without its effects applied.

    Args:
        layer: A layer object

    Returns:
        int: Width of the layer in pixels.
    """
    with suppress(Exception):
        # Try getting bounds no effects
        d = get_layer_action_ref(layer)
        bounds = d.getObjectValue(sID('boundsNoEffects'))
        return bounds.getInteger(sID('right')) - bounds.getInteger(sID('left'))
    return get_layer_width(layer)

src.helpers.bounds.get_height_no_effects(layer: Union[ArtLayer, LayerSet]) -> int

Returns the height of a given layer without its effects applied.

Parameters:

Name Type Description Default
layer ArtLayer | LayerSet

A layer object

required

Returns:

Name Type Description
int int

Height of the layer in pixels.

Source code in src\helpers\bounds.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def get_height_no_effects(layer: Union[ArtLayer, LayerSet]) -> int:
    """Returns the height of a given layer without its effects applied.

    Args:
        layer: A layer object

    Returns:
        int: Height of the layer in pixels.
    """
    with suppress(Exception):
        # Try getting bounds no effects
        d = get_layer_action_ref(layer)
        bounds = d.getObjectValue(sID('boundsNoEffects'))
        return bounds.getInteger(sID('bottom')) - bounds.getInteger(sID('top'))
    return get_layer_height(layer)

src.helpers.bounds.check_textbox_overflow(layer: ArtLayer) -> bool

Check if a TextLayer overflows the bounding box.

Parameters:

Name Type Description Default
layer ArtLayer

ArtLayer with "kind" of TextLayer.

required

Returns:

Type Description
bool

True if text overflowing, else False.

Source code in src\helpers\bounds.py
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def check_textbox_overflow(layer: ArtLayer) -> bool:
    """Check if a TextLayer overflows the bounding box.

    Args:
        layer: ArtLayer with "kind" of TextLayer.

    Returns:
        True if text overflowing, else False.
    """
    # Create a test layer to check the difference
    height = get_layer_dimensions(layer)['height']
    layer.textItem.height = 1000
    dif = get_layer_dimensions(layer)['height'] - height
    undo_action()
    if dif > 0:
        return True
    return False

src.helpers.bounds.get_textbox_bounds(layer: ArtLayer) -> LayerBounds

Get the bounds of a TextLayer's bounding box.

Parameters:

Name Type Description Default
layer ArtLayer

ArtLayer with "kind" of TextLayer.

required

Returns:

Type Description
LayerBounds

List of bounds integers.

Source code in src\helpers\bounds.py
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
def get_textbox_bounds(layer: ArtLayer) -> LayerBounds:
    """Get the bounds of a TextLayer's bounding box.

    Args:
        layer: ArtLayer with "kind" of TextLayer.

    Returns:
        List of bounds integers.
    """
    d = get_layer_action_ref(layer)
    bounds = d.getObjectValue(sID('boundingBox'))
    return (
        bounds.getInteger(sID('left')),
        bounds.getInteger(sID('top')),
        bounds.getInteger(sID('right')),
        bounds.getInteger(sID('bottom'))
    )

src.helpers.bounds.get_textbox_dimensions(layer: ArtLayer) -> type[TextboxDimensions]

Get the dimensions of a TextLayer's bounding box.

Parameters:

Name Type Description Default
layer ArtLayer

ArtLayer with "kind" of TextLayer.

required

Returns:

Type Description
type[TextboxDimensions]

Dict containing width and height.

Source code in src\helpers\bounds.py
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
def get_textbox_dimensions(layer: ArtLayer) -> type[TextboxDimensions]:
    """Get the dimensions of a TextLayer's bounding box.

    Args:
        layer: ArtLayer with "kind" of TextLayer.

    Returns:
        Dict containing width and height.
    """
    d = get_layer_action_ref(layer)
    bounds = d.getObjectValue(sID('boundingBox'))
    return {
        'width': bounds.getInteger(sID('width')),
        'height': bounds.getInteger(sID('height'))
    }

src.helpers.bounds.get_textbox_width(layer: ArtLayer) -> int

Get the width of a TextLayer's bounding box.

Parameters:

Name Type Description Default
layer ArtLayer

ArtLayer with 'kind' of TextLayer.

required

Returns:

Type Description
int

Width of the textbox.

Source code in src\helpers\bounds.py
250
251
252
253
254
255
256
257
258
259
260
261
def get_textbox_width(layer: ArtLayer) -> int:
    """Get the width of a TextLayer's bounding box.

    Args:
        layer: ArtLayer with 'kind' of TextLayer.

    Returns:
        Width of the textbox.
    """
    d = get_layer_action_ref(layer)
    bounds = d.getObjectValue(sID('boundingBox'))
    return bounds.getInteger(sID('width'))

src.helpers.bounds.get_textbox_height(layer: ArtLayer) -> int

Get the height of a TextLayer's bounding box.

Parameters:

Name Type Description Default
layer ArtLayer

ArtLayer with 'kind' of TextLayer.

required

Returns:

Type Description
int

Height of the textbox.

Source code in src\helpers\bounds.py
264
265
266
267
268
269
270
271
272
273
274
275
def get_textbox_height(layer: ArtLayer) -> int:
    """Get the height of a TextLayer's bounding box.

    Args:
        layer: ArtLayer with 'kind' of TextLayer.

    Returns:
        Height of the textbox.
    """
    d = get_layer_action_ref(layer)
    bounds = d.getObjectValue(sID('boundingBox'))
    return bounds.getInteger(sID('height'))