The loader module

The loader module depends on the MagickWand C-library. Make sure it is installed before using this module.

On Linux and MacOS, the loader module will try to search for MagickWand in the folder set by the environment variable MAGICK_HOME. This is substantially faster than the alternate method so it is recommended to set this environment variable before importing Loader.

from chafa.loader import Loader
import chafa

config = chafa.CanvasConfig()
canvas = chafa.Canvas(config)

loader = Loader("./example.jpg")

canvas.draw_all_pixels(
    loader.pixel_type,
    loader.get_pixels(),
    loader.width,
    loader.height,
    loader.rowstride
)

print(canvas.print().decode())

Loader

The Loader is a reasonably fast way to load the pixel data of an image for use with chafa.py. In addition to loading the pixel data, the Loader will also provide useful information such as the width and height of the image to further simplify drawing to the chafa.Canvas.

class chafa.loader.Loader(path: str)
Parameters:

path (str) – The path to the image to load. This will not resolve special characters such as ~.

Raises:

FileNotFoundError – if the image does not exist.

property width
Type:

int

The width of the image.

property height
Type:

int

The height of the image.

property channels
Type:

int

The number of output of get_pixels().

property pixel_type
Type:

chafa.PixelType

The chafa.PixelType of the output of get_pixels().

property rowstride
Type:

int

The rowstride of the image.

get_pixels()
Return type:

ctypes.Array

Returns the pixel data of the image.