ImageRenderer

Qualified name: manimpango.renderer.ImageRenderer

class ImageRenderer

ImageRenderer is a renderer which renders the Layout to an image buffer. You can directly use the buffer or else you can save it to a file, as a png file, using the save() method.

The file_name is optional, if you don’t provide it then you can use the get_buffer() method to get the buffer.

Parameters
  • width (float) – The width of the PNG.

  • height (float) – The height of the PNG.

  • layout (Layout) – The Layout that needs to be rendered.

  • file_name (str) – The path to render the PNG file to.

Example

>>> import manimpango as mp
>>> a = mp.ImageRenderer(100, 100, mp.Layout('hello'), 'test.png')
>>> a
<ImageRenderer file_name='test.png' width=100.0 height=100.0 layout=<Layout text='hello' markup=None>
>>> a.render()
True
>>> a.save()
'test.png'
Raises

Exception – Any error reported by cairo.

Methods

get_buffer

This method returns the buffer of the image.

render

render() actually does the rendering.

save

This method is to save the image to an PNG image.

file_name

The file_name where the file is rendered onto

get_buffer()

This method returns the buffer of the image. This contains the image in the format of ARGB32.

Returns

The buffer of the image.

Return type

bytes

height

The height of the PNG.

layout

The Layout which is being rendered.

render()

render() actually does the rendering. Any error reported by Cairo is reported as an exception. If this method suceeds you can expect an valid image in the buffer.

Returns

True if the function worked, else False.

Return type

bool

save()

This method is to save the image to an PNG image. Note that only PNG image are supported, if you need other formats, use external libraries such as Pillow.

Parameters

file_name – The file_name to write the image to.

Raises

ValueError – Raised when the file_name parameter is None.

Returns

The filepath to the saved file.

Return type

str

stride

The stride of the PNG.

width

The width of the PNG.