Text attributes

class img_gen.Typography(content: str, align: TypographyAlign | None = None, color: ColorKind | None = None, line: Line | None = None, overflow: bool = False, font: Font | None = None, border: Border | None = None)

An attribute to represent a [Layer](struct@crate::Layer)’s rendered text.

align

The alignment of the text.

as_json_str()

Serialize the Typography object to a JSON string.

as_yaml_str()

Serialize the Typography object to a YAML string.

border

The border (if specified) to draw around the rendered glyphs of the content.

color

The color used to fill the rendered text.

content

The text content.

font

The Font property used to describe the font used to render the text.

static from_json_str(json_str)

Deserialize a Typography object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a Typography object from a YAML string.

line

The Line property used to describe the text’s size.

overflow

Controls how text that doesn’t fit within the layer’s bounds is handled.

  • true: the font size is progressively reduced until all text fits within the layer.

  • false: text wraps within the layer’s horizontal boundary; any text that still overflows is replaced with a trailing ellipsis ().

class img_gen.Font(family: str = 'Roboto', style: str | None = None, weight: Weight | None = None, subset: str | None = None, path: str | None = None)

A property to implicitly describe the font used in a [Typography](struct@super::Typography) attribute.

as_json_str()

Serialize the Font object to a JSON string.

as_yaml_str()

Serialize the Font object to a YAML string.

family

The font family’s name.

static from_json_str(json_str)

Deserialize a Font object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a Font object from a YAML string.

path

An optional path to the font’s .ttf file.

style

The font family’s style.

subset

The font family’s lingual subset.

The valid options for this can vary depending on the chosen font family.

weight

The font’s Weight.

class img_gen.Line(amount: int = 1, height: float = 1.0)

A property to implicitly describe the size of the text in a [Typography](struct@super::Typography) attribute.

amount

Returns the current line amount.

as_json_str()

Serialize the Line object to a JSON string.

as_yaml_str()

Serialize the Line object to a YAML string.

static from_json_str(json_str)

Deserialize a Line object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a Line object from a YAML string.

height

Returns the current line height.

class img_gen.Weight

An enumeration of the possible font weights.

Thin = Weight.Thin
Light = Weight.Light
Regular = Weight.Regular
Medium = Weight.Medium
Bold = Weight.Bold
Black = Weight.Black
class img_gen.TypographyAlign

A enumeration of the possible alignment options for the text in a [Typography] attribute.

StartTop = TypographyAlign.StartTop
StartCenter = TypographyAlign.StartCenter
StartBottom = TypographyAlign.StartBottom
CenterTop = TypographyAlign.CenterTop
Center = TypographyAlign.Center
CenterCenter = TypographyAlign.CenterCenter
CenterBottom = TypographyAlign.CenterBottom
EndTop = TypographyAlign.EndTop
EndCenter = TypographyAlign.EndCenter
EndBottom = TypographyAlign.EndBottom