Layout

class img_gen.Layout(size: Size | None = None, layers: list[Layer] = [], debug: Optional[Debug])

A data structure used to represent a generated image’s layout.

append_layer(layer)

Append a single Layer to the layout’s list of layers.

as_json_str()

Serialize the Layout object to a JSON string.

as_yaml_str()

Serialize the Layout object to a YAML string.

debug

An optional Debug attribute can be used to show the constraints of the Layout’s layers.

extend_layers(layers)

Extend the layout’s list of layers with an iterable of Layer objects.

static from_json_str(yaml_str)

Deserialize a Layout object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a Layout object from a YAML string.

layers

A list of the layout’s Layer objects.

size

The layout’s Size

class img_gen.Size(width: int = None, height: int = None)

A layer attribute to describe the layer’s size.

as_json_str()

Serialize the Size object to a JSON string.

as_yaml_str()

Serialize the Size object to a YAML string.

static from_json_str(json_str)

Deserialize a Size object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a Size object from a YAML string.

height

The current height.

width

The current width.

class img_gen.Debug(enable: bool = False, grid: bool = True, grid_step: int = 16, color: Color | None = None)

A struct to describe a [Layout]’s visual debug output.

as_json_str()

Serialize the Debug object to a JSON string.

as_yaml_str()

Serialize the Debug object to a YAML string.

color

The color used to outline debug output.

enable

A flag to enable or disable the debug output.

static from_json_str(json_str)

Deserialize a Debug object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a Debug object from a YAML string.

get_foreground_color() SolidColor

Calculate a black or white foreground color using Debug.color as a background.

grid

A flag to control if the debug output shall show a grid of points over the layout.

grid_step

The space between points on the debug output’s grid.