A Python implementation of stewartlord/identicon.js with additional features:
- Support for larger identicons with 7×7 grid (more detailed)
- Enhanced color palette for more colorful identicons
- Pure Python implementation using Pillow
- Clone this repository:
git clone https://github.com/your-username/identicon-python.git
cd identicon-python- Install requirements:
pip install -r requirements.txtGenerate an identicon for a username:
python generate_identicon.py usernameThis will save the identicon as identicons/username.png.
from identicon import Identicon
# Simple usage
identicon = Identicon("your-username")
identicon.save("username.png")
# Advanced usage with options
options = {
'size': 420, # Size in pixels
'margin': 0.1, # Margin as a decimal (0.1 = 10%)
'saturation': 0.8, # Color saturation (0-1)
'brightness': 0.6, # Color brightness (0-1)
'background': (255, 255, 255, 255), # RGBA background color
}
# Using a hash directly
identicon = Identicon("3f4a4e062756c75917f6d2b39166b5b8", options)
identicon.save("custom.png")
# Generate and get base64 encoded image
base64_data = identicon.to_base64()
print(f"data:image/png;base64,{base64_data}")Run the demo script to generate various identicons:
python demo.pyThis will create sample identicons in the demo/ directory.
The identicon generator creates a 7×7 symmetric grid pattern based on a hash value (typically an MD5 hash of a username). Each cell in the grid is either on or off, determined by bits from the hash. The foreground color is also derived from the hash.
The resulting image is a unique, recognizable icon that can be used for user avatars.
- Original implementation: stewartlord/identicon.js
- The creative visual design is borrowed from Jason Long of Git and GitHub fame.