Simple Example

The simplest way to render a text into a image create a new instance of Layout and then a renderer and call the Layout.render().

from manimpango import *
l = Layout("Hello World")
r = ImageRenderer(400, 400, l, "test.png")

This will create a 400x400 image with the text “Hello World” in it at the position (0, 0) in the image.

Calculating Bounding Box

The bounding box of the text can be obtained by calling the Layout.get_bounding_box() method. This will return a tuple of the form (x, y, width, height).

>>> from manimpango import *
>>> l = Layout("Hello World")
>>> print(l.get_bounding_box())
(0, 0, 90, 19)

The bounding box is the smallest rectangle that contains all the glyphs of the text.

Changing the Font

The font can be changed by passing a FontDescription while creating the Layout.

>>> from manimpango import *
>>> l = Layout("Hello World", font_desc=FontDescription.from_string("Arial 60"))
>>> l.render('test.png')

The font description can also be changed after the Layout has been created by setting the Layout.font_desc attribute.