Skip to main content

ImageText

ClassSource

ImageText(
text: str,
font: str | PathLike[str] | FontInfo | None = None,
font_size: int | str | ImageFontSize | ImageFontAbsSize = ImageFontSize.h2,
pad_size: int = 0,
color: str | tuple[float, ...] = "#FFFFFF",
)

A layer of text that can be rendered as an image.

The image will be rendered every time when it is accessed.

Arguments​

Requires​

NameTypeRequired
Description
textstrThe text to be rendered.
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 | ImageFontSize | ImageFontAbsSizeThe dynamic font size of the rendered text. If using int, this size will be absolute.
pad_sizeintThe size used for padding on all sides of the text.
colorstr | tuple[float, ...]The text color.

Methods​

copy​

v_1: Self = self.copy()

Get a copy of this instance.

Returns​

NameType
Description
v_1SelfThe copied text image.

Properties​

font_size​

font_size: ImageFontAbsSize | ImageFontSize = self.font_size

The font size (dynamic or absolute size).


height​

height: int = self.height

The height of the text image.


img​

img: Image = self.img

Render the text as an image, and get the pixel-based image.


size​

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

The (width, height) shape of the text image.


text​

text: str = self.text

The text to be rendered.


width​

width: int = self.width

The width of the text image.