generativepy.utils module

Martin McBride, 2020-11-25
Tags gif
Categories generativepy generative art

generativepy has moved to the website, and this page might not be up to date. Please visit the new location.

The utils module contains several utility functions that are generally useful within generativepy.


Mainly for internal use with Pycairo data.

generativepy.utils.correct_pycairo_byte_order(array, channels)
Parameter Type Description
array array NumPy array of image data
channels int Number of channels in the data

Pycairo stores image data using a single 32-bit word per pixel (storing 8 bits each of R, G, B and optional Alpha).

When this is converted to a NumPy array, each 32-bit word is copie dinto memory, then NumPy treats it as 4 bytes. The order of the 4 bytes depends on the endian-ness of the processor. If the processor is little-endian, the ordering will be incorrect, leading to incorrect colours.

The function checks the processor endian-ness, and reorders the data if needed. It returns the adjusted array.


Creates a filename in the system temp files area.

Parameter Type Description
names string(s) One or more path parts.

Takes a filename or partial path string, and return a full pathname that will create a file in the temp area.

For a file:


Will return a path (on a linux system) of:


and on a Windows system:


For a subfolder and file:

temp_file('myfolder', 'myimage.png')

Will return a path (on a linux system) of:


and on a Windows system:


The folder used as system folder may be different depending on how your system is configured. This function only return the path string, it will not create the folders or files.