Files
go-jdenticon/README.md
Kevin McIntyre f84b511895 init
2025-06-18 01:00:00 -04:00

106 lines
2.4 KiB
Markdown

# [Jdenticon-go](https://jdenticon.com)
Go library for generating highly recognizable identicons.
![Sample identicons](https://jdenticon.com/hosted/github-samples.png)
## Features
go-jdenticon is a Go port of the JavaScript library [Jdenticon](https://github.com/dmester/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
```bash
go get github.com/kevin/go-jdenticon
```
## Usage
### Basic Usage
```go
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
```go
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
```bash
# 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 settings
- `GenerateWithConfig(value string, size int, config *Config) *Icon` - Generate with custom configuration
- `DefaultConfig() *Config` - Get default configuration settings
### Types
#### Icon
- `ToSVG() string` - Render as SVG string
- `ToPNG() []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](https://github.com/dmester/jdenticon) project for details.
## Contributing
Contributions are welcome! Please ensure all tests pass and follow Go conventions.
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests if applicable
5. Submit a pull request