Generator(rows, columns, digest=<built-in function openssl_md5>, foreground=['#000000'], background='#ffffff')¶
Factory class that can be used for generating the identicons deterministically based on hash of the passed data.
Resulting identicons are images of requested size with optional padding. The identicon (without padding) consists out of M x N blocks, laid out in a rectangle, where M is the number of blocks in each column, while N is number of blocks in each row.
Each block is a smallself rectangle on its own, filled using the foreground or background colour.
The foreground is picked randomly, based on the passed data, from the list of foreground colours set during initialisation of the generator.
The blocks are always laid-out in such a way that the identicon will be symterical by the Y axis. The center of symetry will be the central column of blocks.
Simply put, the generated identicons are small symmetric mosaics with optional padding.
generate(data, width, height, padding=(0, 0, 0, 0), output_format='png', inverted=False)¶
Generates an identicon image with requested width, height, padding, and output format, optionally inverting the colours in the indeticon (swapping background and foreground colours) if requested.
data - Hashed or raw data that will be used for generating the identicon.
width - Width of resulting identicon image in pixels.
height - Height of resulting identicon image in pixels.
padding - Tuple describing padding around the generated identicon. The tuple should consist out of four values, where each value is the number of pixels to use for padding. The order in tuple is: top, bottom, left, right.
output_format - Output format of resulting identicon image. Supported formats are anything that is supported by Pillow, plus a special “ascii” mode.
inverted - Specifies whether the block colours should be inverted or not. Default is False.
Returns:Byte representation of an identicon image.