Skip to content

Absolute

AbsolutePosition

Bases: BaseModel

Represents an absolute positioning.

type class-attribute instance-attribute

type: Literal['absolute'] = 'absolute'

The type of positioning. Defaults to "absolute".

x class-attribute instance-attribute

The x-coordinate of the assets.

y class-attribute instance-attribute

The y-coordinate of the assets.

from_relative classmethod

from_relative(
    position: RelativePosition, frame_size: FrameSize
) -> AbsolutePosition

Creates an absolute positioning from a relative positioning.

Parameters:

Name Type Description Default
position RelativePosition

The relative positioning.

required
frame_size FrameSize

The size of the frame.

required

Returns:

Type Description
AbsolutePosition

The absolute positioning.

Source code in src/mosaico/positioning/absolute.py
@classmethod
def from_relative(cls, position: RelativePosition, frame_size: FrameSize) -> AbsolutePosition:
    """
    Creates an absolute positioning from a relative positioning.

    :param position: The relative positioning.
    :param frame_size: The size of the frame.
    :return: The absolute positioning.
    """
    frame_max_width, frame_max_height = frame_size
    return cls(x=int(position.x * frame_max_width), y=int(position.y * frame_max_height))

from_region classmethod

from_region(
    position: RegionPosition, frame_size: FrameSize
) -> AbsolutePosition

Creates an absolute positioning from a region positioning.

Parameters:

Name Type Description Default
position RegionPosition

The region positioning.

required
frame_max_width

The maximum width of the frame.

required
frame_max_height

The maximum height of the frame.

required

Returns:

Type Description
AbsolutePosition

The absolute positioning.

Source code in src/mosaico/positioning/absolute.py
@classmethod
def from_region(cls, position: RegionPosition, frame_size: FrameSize) -> AbsolutePosition:
    """
    Creates an absolute positioning from a region positioning.

    :param position: The region positioning.
    :param frame_max_width: The maximum width of the frame.
    :param frame_max_height: The maximum height of the frame.
    :return: The absolute positioning.
    """
    frame_max_width, frame_max_height = frame_size
    x_map = {"left": 0, "center": frame_max_width // 2, "right": frame_max_width}
    y_map = {"top": 0, "center": frame_max_height // 2, "bottom": frame_max_height}
    return cls(x=x_map[position.x], y=y_map[position.y])