Image and background attributes

class img_gen.Background(image: str = None, color: ColorKind = None, preserve_aspect: PreserveAspect = None)

An attribute to describe a [Layer](struct@crate::Layer)’s background.

as_json_str()

Serialize the Background object to a JSON string.

as_yaml_str()

Serialize the Background object to a YAML string.

color

A color overlaid on top of the image. If no image is specified, then the layer is simple filled with this color.

static from_json_str(json_str)

Deserialize a Background object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize a Background object from a YAML string.

image

A path to an image file.

If the given image path has no file extension, then it will be treated as an SVG image.

This also supports built-in SVG icons from the following icon packs:

  • Material Design Icons (material/{icon_slug})

  • Simple Icons (simple/{icon_slug})

  • Octicons (octicons/{icon_slug})

  • FontAwesome Free (fontawesome/<brands|solid|regular>/{icon_slug})

Otherwise, the image file’s path is resolved via a search through the list of external_resource_paths provided to the Generator (in img_gen_renderer crate), which defaults to the current working directory if unspecified or an empty list.

preserve_aspect

This controls how the original image is rendered into the layer. Default is to preserve the original image’s width and height.

class img_gen.Icon(image: str, color: ColorKind = None, preserve_aspect: PreserveAspect | None = None)

An attribute to describe a [Layer](struct@crate::Layer)’s [Icon].

as_json_str()

Serialize the Icon object to a JSON string.

as_yaml_str()

Serialize the Icon object to a YAML string.

color

A color used to replace the [Icon::image]’s original coloring.

static from_json_str(json_str)

Deserialize an Icon object from a JSON string.

static from_yaml_str(yaml_str)

Deserialize an Icon object from a YAML string.

image

A path to an image file.

If the given image path has no file extension, then it will be treated as an SVG image.

This also supports built-in SVG icons from the following icon packs:

  • Material Design Icons (material/{icon_slug})

  • Simple Icons (simple/{icon_slug})

  • Octicons (octicons/{icon_slug})

  • FontAwesome Free (fontawesome/<brands|solid|regular>/{icon_slug})

Otherwise, the image file’s path is resolved via a search through the list of external_resource_paths provided to the Generator (in img_gen_renderer crate), which defaults to the current working directory if unspecified or an empty list.

preserve_aspect

This controls how the original image is rendered into the layer.

The default is to preserve the original image’s width and height ([PreserveAspect::On]).

class img_gen.PreserveAspect

An enum to describe the how to preserve an image’s dimensions when portrayed in an [Icon] or [Background] attribute.

On = PreserveAspect.On
Off = PreserveAspect.Off
Width = PreserveAspect.Width
Height = PreserveAspect.Height