generativepy.utils module


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

generativepy has moved to the pythoninformer.com 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.

correct_pycairo_byte_order

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.

temp_file

Creates a filename in the system temp files area.

generativepy.utils.temp_file(*names)
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:

temp_file('myimage.png')

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

'/tmp/myimage.png'

and on a Windows system:

'c:\temp\myimage.png'

For a subfolder and file:

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

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

'/tmp/myfolder/myimage.png'

and on a Windows system:

'c:\temp\myfolder\myimage.png'

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.