Skip to main content

ImageMultiLayer

ClassSource

ImageMultiLayer(width: int, height: int, fmt: str | ImageFormat = "png")
ImageMultiLayer(size: tuple[int, int], fmt: str | ImageFormat = "png")
ImageMultiLayer(
img: ImageSingle, name: str, fmt: str | ImageFormat | None = None
)
ImageMultiLayer(
img: ImageLayer | ImageMultiLayer, fmt: str | ImageFormat | None = None
)

The handle of a stack of layered images.

This class is inspired by the image editing software.

All modifications to this class is INPLACE. If the non-inplace modification is required, please use copy() method.

Arguments​

Initialization.

ver. 1​

NameTypeRequired
Description
widthintThe width of the canvas (this multi-layered image).
heightintThe height of the canvas (this multi-layered image).
fmtstr | ImageFormatThe format of the image. It is used only when saving this image.

ver. 2​

NameTypeRequired
Description
sizetuple[int, int]The (width, height) of the canvas (this multi-layered image).
fmtstr | ImageFormatThe format of the image. It is used only when saving this image.

ver. 3​

NameTypeRequired
Description
imgImageSingleThe image used as the first layer of this multi-layered image. The canvas size will be the same as this image size.
namestrThe name of the first image layer (the layer is specified by img).
fmtstr | ImageFormat | NoneThe format of the image. It is used only when saving this image.

ver. 4​

NameTypeRequired
Description
imgImageLayer | ImageMultiLayerThe image used for initializing this image. If it is ImageLayer, will use this layer as the first layer. If it is ImageMultiLayer, will make a copy of the given img.
fmtstr | ImageFormat | NoneThe format of the image. It is used only when saving this image.

Methods​

add_background​

v_1: Self = self.add_background(
color: str | tuple[float, ...] = "#1b2838", name: str = "background"
)

Add a background layer to this multi-layered image.

This method is inplace.

Requires​

NameTypeRequired
Description
colorstr | tuple[float, ...]The color of the background to be added.
namestrThe name of the added background layer.

Returns​

NameType
Description
v_1SelfThe inplace-modified multi-layered image.

add_image​

v_1: Self = self.add_image(
img: ImageSingle | ImageText,
name: str,
anchor: str | ImageAnchor = ImageAnchor.center,
related_to: str | None = None,
rel_anchor: str | ImageAnchor = ImageAnchor.center,
pos_shift: tuple[int, int] | None = None,
)

Add an image layer to this multi-layered image.

This method is inplace.

Requires​

NameTypeRequired
Description
imgImageSingle | ImageTextThe image to be added.
namestrThe name of the added image layer.
anchorstr | ImageAnchorThe anchor of this image.
related_tostr | None

The name of another image layer. When rendering the image, will place this image based on the position of the image specified by related_to.

If not specified, the image layer will be put related to the canvas.

rel_anchorstr | ImageAnchorThe anchor of the reference image specified by related_to when placing this image.
pos_shifttuple[int, int] | NoneThe (h_shift, v_shift) of this image position. If not specified, will use (0, 0).

Returns​

NameType
Description
v_1SelfThe inplace-modified multi-layered image.

add_latex​

v_1: Self = self.add_latex(
equation: str,
name: str,
template: str | TeXTemplate = "default",
font_size: str | ImageFontSize = ImageFontSize.h2,
color: str | tuple[float, ...] = "#FFFFFF",
stroke_color: str | tuple[float, ...] | None = None,
glow_color: str | tuple[float, ...] | None = None,
shadow_color: str | tuple[float, ...] | None = None,
anchor: str | ImageAnchor = ImageAnchor.center,
related_to: str | None = None,
rel_anchor: str | ImageAnchor = ImageAnchor.center,
pos_shift: tuple[int, int] | None = None,
)

Add a LaTeX equation layer to this multi-layered image.

This method is inplace.

Requires​

NameTypeRequired
Description
equationstr

The LaTeX equation to be rendered.

Do not add $ or $$ symbol to the equation.

namestrThe name of the added equation (text) layer.
templatestr | TeXTemplate

The LaTeX template used for rendering the equation. If using str, will treat this value as the template name.

The available templates can be found in improc.variables.tex_templates.

font_sizestr | ImageFontSizeThe dynamic font size of the rendered text.
colorstr | tuple[float, ...]The text color.
stroke_colorstr | tuple[float, ...] | NoneThe text stroke color. If not specified, will not add a stroke to the text.
glow_colorstr | tuple[float, ...] | NoneThe text glow color. If not specified, will not add a glow to the text.
shadow_colorstr | tuple[float, ...] | NoneThe text shadow color. If not specified, will not add a shadow to the text.
anchorstr | ImageAnchorThe anchor of this image.
related_tostr | None

The name of another image layer. When rendering the image, will place this image based on the position of the image specified by related_to.

If not specified, the image layer will be put related to the canvas.

rel_anchorstr | ImageAnchorThe anchor of the reference image specified by related_to when placing this image.
pos_shifttuple[int, int] | NoneThe (h_shift, v_shift) of this image position. If not specified, will use (0, 0).

Returns​

NameType
Description
v_1SelfThe inplace-modified multi-layered image.

add_text​

v_1: Self = self.add_text(
text: str,
name: str,
font: str | PathLike[str] | FontInfo | None = None,
font_size: int | str | ImageFontAbsSize | ImageFontSize = ImageFontSize.h2,
color: str | tuple[float, ...] = "#FFFFFF",
stroke_color: str | tuple[float, ...] | None = None,
glow_color: str | tuple[float, ...] | None = None,
shadow_color: str | tuple[float, ...] | None = None,
anchor: str | ImageAnchor = ImageAnchor.center,
related_to: str | None = None,
rel_anchor: str | ImageAnchor = ImageAnchor.center,
pos_shift: tuple[int, int] | None = None,
)

Add a text layer to this multi-layered image.

This method is inplace.

Requires​

NameTypeRequired
Description
textstrThe text to be rendered.
namestrThe name of the added text layer.
fontstr | PathLike[str] | FontInfo | NoneThe path of the font, or the searched font used for rendering the text. If not specified, will use the default font.
font_sizeint | str | ImageFontAbsSize | ImageFontSizeThe dynamic font size of the rendered text. If using int, this size will be absolute.
colorstr | tuple[float, ...]The text color.
stroke_colorstr | tuple[float, ...] | NoneThe text stroke color. If not specified, will not add a stroke to the text.
glow_colorstr | tuple[float, ...] | NoneThe text glow color. If not specified, will not add a glow to the text.
shadow_colorstr | tuple[float, ...] | NoneThe text shadow color. If not specified, will not add a shadow to the text.
anchorstr | ImageAnchorThe anchor of this image.
related_tostr | None

The name of another image layer. When rendering the image, will place this image based on the position of the image specified by related_to.

If not specified, the image layer will be put related to the canvas.

rel_anchorstr | ImageAnchorThe anchor of the reference image specified by related_to when placing this image.
pos_shifttuple[int, int] | NoneThe (h_shift, v_shift) of this image position. If not specified, will use (0, 0).

Returns​

NameType
Description
v_1SelfThe inplace-modified multi-layered image.

convert​

v_1: Self = self.convert(mode: str)

Convert the image mode.

This method is inplace.

Requires​

NameTypeRequired
Description
modestrThe mode of the converted image.

Returns​

NameType
Description
v_1SelfThe inplace-modified multi-layered image.

flatten​

v_1: ImageSingle = self.flatten()

Flatten this image as a single-layer image.

This method is non-inplace.

Returns​

NameType
Description
v_1ImageSingleThe flattened single-layer image.

save​

self.save(
fobj: str | PathLike[str] | IO[bytes],
quality: str | ImageQuality = ImageQuality.high,
)

Save the image as a file.

Before saving the image, this method will run optimizations corresponding to the saving format.

Requires​

NameTypeRequired
Description
fobjstr | PathLike[str] | IO[bytes]The file path of file-like object of the output file.
qualitystr | ImageQualityThe quality of the image to be saved.

save_steam_screenshot​

self.save_steam_screenshot(
folder_path: str | PathLike[str],
file_name: str,
quality: str | ImageQuality = ImageQuality.high,
skip_thumbnails: bool = False,
)

Save the image as a Steam screenshot.

When using this method to save the image, we will create a "thumbnails" folder where we save the image, and save the small version (thumbnail image) in the "thumbnails" folder.

Requires​

NameTypeRequired
Description
folder_pathstr | PathLike[str]The path of the folder where we save the image.
file_namestrThe name of the saved screenshot file.
qualitystr | ImageQualityThe quality of the image to be saved.
skip_thumbnailsboolA flag. If specified, will not save thumbnails.

Properties​

size​

size: tuple[int, int] = self.size

The (width, height) shape of this image.