f84b5118959e1b85dd26f473ffc7050ccf375867
Jdenticon-go
Go library for generating highly recognizable identicons.
Features
go-jdenticon is a Go port of the JavaScript library Jdenticon.
- Renders identicons as PNG or SVG with no external dependencies
- Generates consistent, deterministic identicons from any input string
- Highly customizable color themes and styling options
- Simple, clean API for easy integration
- Command-line tool included for standalone usage
Installation
go get github.com/kevin/go-jdenticon
Usage
Basic Usage
package main
import (
"fmt"
"github.com/kevin/go-jdenticon/jdenticon"
)
func main() {
// Generate an identicon
icon := jdenticon.Generate("user@example.com", 200)
// Get SVG output
svg := icon.ToSVG()
fmt.Println(svg)
// Get PNG output
png := icon.ToPNG()
// Save or use PNG data...
}
Custom Configuration
config := &jdenticon.Config{
Hue: 0.3,
Saturation: 0.7,
Lightness: 0.5,
Padding: 0.1,
}
icon := jdenticon.GenerateWithConfig("user@example.com", 200, config)
Command Line Tool
# Generate SVG
go run cmd/jdenticon/main.go -value "user@example.com" -size 200
# Generate PNG file
go run cmd/jdenticon/main.go -value "user@example.com" -format png -output icon.png
API Reference
Functions
Generate(value string, size int) *Icon- Generate an identicon with default settingsGenerateWithConfig(value string, size int, config *Config) *Icon- Generate with custom configurationDefaultConfig() *Config- Get default configuration settings
Types
Icon
ToSVG() string- Render as SVG stringToPNG() []byte- Render as PNG byte data
Config
Hue float64- Color hue (0.0-1.0)Saturation float64- Color saturation (0.0-1.0)Lightness float64- Color lightness (0.0-1.0)BackgroundColor string- Background color (hex or empty for transparent)Padding float64- Padding as percentage of size (0.0-0.5)
License
MIT License - see the original Jdenticon project for details.
Contributing
Contributions are welcome! Please ensure all tests pass and follow Go conventions.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Description
Languages
Go
89.4%
Shell
6.5%
JavaScript
2.6%
Makefile
1.5%