Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterised aspects of the identicon #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

McPo
Copy link

@McPo McPo commented May 29, 2018

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)

@McPo
Copy link
Author

McPo commented Feb 4, 2019

Is there anything preventing this from being merged?

@colin-byrne-1
Copy link

@flavono123 ?

Copy link
Owner

@flavono123 flavono123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very sorry for my late

@@ -48,7 +48,7 @@ def _extract_color(hex_list):
r,g,b =tuple(hex_list[i:i+2]
for i in range(0, 2*3, 2))

return f'#{r}{g}{b}'
return '#{r}{g}{b}'.format(r=r,g=g,b=b)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to show the reference link on it, use format() rather than f sigil

@flavono123 flavono123 assigned flavono123 and McPo and unassigned flavono123 Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants