Colors

class img_gen.ColorKind

An enum to describe the possible kinds of colors used when rendering various [Layer](struct@crate::Layer) attributes/properties.

SolidColor : Callable[[Color], ColorKind]

Pass an instance of Color to the parameter of this constructor.

LinearGradient : Callable[[LinearGradient], ColorKind]

Pass an instance of LinearGradient to the parameter of this constructor.

RadialGradient : Callable[[RadialGradient], ColorKind]

Pass an instance of RadialGradient to the parameter of this constructor.

ConicalGradient : Callable[[ConicalGradient], ColorKind]

Pass an instance of ConicalGradient to the parameter of this constructor.

Solid color

class img_gen.SolidColor(r: int = 0, g: int = 0, b: int = 0, a: int = 0)

A class to represent a solid color.

Instantiate a Color from a 4 unsigned integers in range [0, 255]. Each parameter corresponds to the Color attributes:

  • r for red

  • g for green

  • b for blue

  • a for alpha (AKA opacity)

a

The color’s alpha component (AKA opacity).

as_json_str()

Serialize the SolidColor object to a JSON string.

as_yaml_str()

Serialize the SolidColor object to a YAML string.

b

The color’s blue component.

static from_json_str(json_str)

Deserialize a SolidColor object from a JSON string.

static from_string(val: str) Color

Instantiate a SolidColor from an string typically used in CSS.

Valid color values include

  • named colors (see CSS specifications)

  • hexadecimal color codes (#f00 or #ff0000 or #ff0000ff)

  • RGB or RGBA strings ("rgb(255, 0, 0)" or "rgba(255, 0, 0, 1.0")

  • HSL or HSLA string ("hsl(0, 1.0, 1.0)" or "hsla(0, 1.0, 1.0, 1.0)")

  • HWB or HWBA string ("hwb(0, 1.0, 1.0)" or "hwba(0, 1.0, 1.0, 1.0)")

  • HSV or HSVA string ("hsv(0, 1.0, 1.0)" or "hsva(0, 1.0, 1.0, 1.0)")

Throws:

A ValueError is raised if the given value is not a proper CSS color value.

static from_yaml_str(yaml_str)

Deserialize a SolidColor object from a YAML string.

g

The color’s green component.

r

The color’s red component.

to_tuple() tuple[int, int, int, int]

Return a 4-integer tuple representing the Color.

Each integer in the tuple will be in range [0, 255] and corresponds to the parameters in the SolidColor constructor.

Gradient colors

class img_gen.ColorGradient(spec: list[tuple[float, str]] | None = None, preset: Preset | None = Presets.MonoChrome)

A class to represent a gradient of colors.

as_json_str()

Serialize the ColorGradient object to a JSON string.

as_yaml_str()

Serialize the ColorGradient object to a YAML string.

static from_json_str(json_str)

Deserialize a ColorGradient object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a ColorGradient object from a YAML string.

class img_gen.Spread

A enumeration to describe gradient spread behavior at the bounds of the gradient.

This only applies to LinearGradient and RadialGradient, not ConicalGradient.

Pad = Spread.Pad
Reflect = Spread.Reflect
Repeat = Spread.Repeat