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
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
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
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
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
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
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
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
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
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
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
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
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
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'))