Skip to content

purr/identicon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Identicon Generator (Python)

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

Installation

  1. Clone this repository:
git clone https://github.com/your-username/identicon-python.git
cd identicon-python
  1. Install requirements:
pip install -r requirements.txt

Usage

Command Line

Generate an identicon for a username:

python generate_identicon.py username

This will save the identicon as identicons/username.png.

Python API

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}")

Demo

Run the demo script to generate various identicons:

python demo.py

This will create sample identicons in the demo/ directory.

How It Works

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.

Credits

  • Original implementation: stewartlord/identicon.js
  • The creative visual design is borrowed from Jason Long of Git and GitHub fame.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages