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
| Name | Type | Required | |
|---|---|---|---|
width | int | The width of the canvas (this multi-layered image). | |
height | int | The height of the canvas (this multi-layered image). | |
fmt | str | ImageFormat | The format of the image. It is used only when saving this image. |
ver. 2
| Name | Type | Required | |
|---|---|---|---|
size | tuple[int, int] | The (width, height) of the canvas (this multi-layered image). | |
fmt | str | ImageFormat | The format of the image. It is used only when saving this image. |
ver. 3
| Name | Type | Required | |
|---|---|---|---|
img | ImageSingle | The image used as the first layer of this multi-layered image. The canvas size will be the same as this image size. | |
name | str | The name of the first image layer (the layer is specified by img). | |
fmt | str | ImageFormat | None | The format of the image. It is used only when saving this image. |
ver. 4
| Name | Type | Required | |
|---|---|---|---|
img | ImageLayer | ImageMultiLayer | The 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. | |
fmt | str | ImageFormat | None | The 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
| Name | Type | Required | |
|---|---|---|---|
color | str | tuple[float, ...] | The color of the background to be added. | |
name | str | The name of the added background layer. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The 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
| Name | Type | Required | |
|---|---|---|---|
img | ImageSingle | ImageText | The image to be added. | |
name | str | The name of the added image layer. | |
anchor | str | ImageAnchor | The anchor of this image. | |
related_to | str | None | The name of another image layer. When rendering the image, will place this image based on the position of the image specified by If not specified, the image layer will be put related to the canvas. | |
rel_anchor | str | ImageAnchor | The anchor of the reference image specified by related_to when placing this image. | |
pos_shift | tuple[int, int] | None | The (h_shift, v_shift) of this image position. If not specified, will use (0, 0). |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The 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
| Name | Type | Required | |
|---|---|---|---|
equation | str | The LaTeX equation to be rendered. Do not add | |
name | str | The name of the added equation (text) layer. | |
template | str | TeXTemplate | The LaTeX template used for rendering the equation. If using The available templates can be found in | |
font_size | str | ImageFontSize | The dynamic font size of the rendered text. | |
color | str | tuple[float, ...] | The text color. | |
stroke_color | str | tuple[float, ...] | None | The text stroke color. If not specified, will not add a stroke to the text. | |
glow_color | str | tuple[float, ...] | None | The text glow color. If not specified, will not add a glow to the text. | |
shadow_color | str | tuple[float, ...] | None | The text shadow color. If not specified, will not add a shadow to the text. | |
anchor | str | ImageAnchor | The anchor of this image. | |
related_to | str | None | The name of another image layer. When rendering the image, will place this image based on the position of the image specified by If not specified, the image layer will be put related to the canvas. | |
rel_anchor | str | ImageAnchor | The anchor of the reference image specified by related_to when placing this image. | |
pos_shift | tuple[int, int] | None | The (h_shift, v_shift) of this image position. If not specified, will use (0, 0). |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The 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
| Name | Type | Required | |
|---|---|---|---|
text | str | The text to be rendered. | |
name | str | The name of the added text layer. | |
font | str | PathLike[str] | FontInfo | None | The path of the font, or the searched font used for rendering the text. If not specified, will use the default font. | |
font_size | int | str | ImageFontAbsSize | ImageFontSize | The dynamic font size of the rendered text. If using int, this size will be absolute. | |
color | str | tuple[float, ...] | The text color. | |
stroke_color | str | tuple[float, ...] | None | The text stroke color. If not specified, will not add a stroke to the text. | |
glow_color | str | tuple[float, ...] | None | The text glow color. If not specified, will not add a glow to the text. | |
shadow_color | str | tuple[float, ...] | None | The text shadow color. If not specified, will not add a shadow to the text. | |
anchor | str | ImageAnchor | The anchor of this image. | |
related_to | str | None | The name of another image layer. When rendering the image, will place this image based on the position of the image specified by If not specified, the image layer will be put related to the canvas. | |
rel_anchor | str | ImageAnchor | The anchor of the reference image specified by related_to when placing this image. | |
pos_shift | tuple[int, int] | None | The (h_shift, v_shift) of this image position. If not specified, will use (0, 0). |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The inplace-modified multi-layered image. |
convert
v_1: Self = self.convert(mode: str)
Convert the image mode.
This method is inplace.
Requires
| Name | Type | Required | |
|---|---|---|---|
mode | str | The mode of the converted image. |
Returns
| Name | Type | |
|---|---|---|
v_1 | Self | The 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
| Name | Type | |
|---|---|---|
v_1 | ImageSingle | The 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
| Name | Type | Required | |
|---|---|---|---|
fobj | str | PathLike[str] | IO[bytes] | The file path of file-like object of the output file. | |
quality | str | ImageQuality | The 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
| Name | Type | Required | |
|---|---|---|---|
folder_path | str | PathLike[str] | The path of the folder where we save the image. | |
file_name | str | The name of the saved screenshot file. | |
quality | str | ImageQuality | The quality of the image to be saved. | |
skip_thumbnails | bool | A flag. If specified, will not save thumbnails. |
Properties
size
size: tuple[int, int] = self.size
The (width, height) shape of this image.