identicon
identicon copied to clipboard
Parameterised aspects of the identicon
Implemented parameters for input_hash_str, image size, padding, background colour, foreground colour, corner radius , lightness, saturation and image type.
input_hash_str allows directly inserting a hash, which allows for other possibilities other than MD5
Background colour and foreground colour can now be set to static colours, or if they are set to None the dynamic colour will be used. This means the foreground can be white and the background can have a dynamic colour instead.
The dynamic colour is now generated using HLS, in the same manner as http://identicon.net. This gives a more consistent look to the generated Identicons. Not sure if your happy accepting the new colour generating algorithm, although it does appear to produce better results.
All the defaults remain the same except for the border_radius it defaults to None. It seemed the most appropriate thing to do.
The motivator for these changes, was that I needed to create a GitHub-esque Identicon, which would be circle cropped (When displayed in a list view, but square when viewed in full). Hence I needed to be able to adjust the padding, such that it looked good when circle cropped. Along with removing the post-process corner radius, and flipping the dynamic colours. Obviously changing the size of the image was also relevant.
This is the code I used to achieve the above.
import math
import base64
import Identicon
size = 192
minimum_padding = (size-math.sqrt(math.pow(size, 2)/2))/2
padding = minimum_padding + 20
icon = Identicon.render('helloworld', size=size, padding=padding, background_color=None, foreground_color=(255,255,255))
print(base64.b64encode(icon))
with open('identicon.png', 'wb') as f:
f.write(icon)
Is there anything preventing this from being merged?
@flavono123 ?