Skip to content

A lightweight Go package to generate unique, symmetric identicons based on an input string. Easily integrate with your Go project to create visual avatars for users.

License

Notifications You must be signed in to change notification settings

rahji/goavatar

 
 

Repository files navigation

Goavatar Identicon Generator in Go

This package provides a simple way to generate unique, symmetric identicons based on an input string (e.g., an email address or username). It uses an MD5 hash to create a deterministic pattern and color scheme, then mirrors the design for a visually appealing avatar.

Example User Avatars

Avatar 1
QuantumNomad42
     Avatar 2
EchoFrost7
     Avatar 3
NebulaTide19
     Avatar 4
ZephyrPulse88
     Avatar 5
EmberNexus23

Examples with Custom-Shaped Pixels

Avatar 6
Shaped fg pixels
     Avatar 7
Shaped fg pixels w/transparency
     Avatar 8
Shaped fg & bg pixels
     Avatar 9
Shaped fg & bg pixels, w/transparency

Installation

To use this package in your Go project, install it via:

go get github.com/MuhammadSaim/goavatar

Then, import it in your Go code:

import "github.com/MuhammadSaim/goavatar"

Examples

See the example folder for a program that creates the identicons found in the arts directory.

Package Documentation

Generate Identicon

func Make(input, ...optFunc) image.Image
  • input: A string used to generate a unique identicon (e.g., email, username).
  • ...optFunc: Functional options to override the default values.
  • image.Image: Function returns an image.Image, allowing the caller to handle image processing, encoding, and storage as needed.

Functional Options

// WithSize sets the size of the avatar.
// It is always square and has a minimum size of 64x64
func WithSize(s int) optFunc

// WithGridSize sets the grid size of the avatar.
func WithGridSize(g int) optFunc

// WithBgColor sets the background color of the avatar.
func WithBgColor(r, g, b, a uint8) optFunc

// WithFgColor sets the foreground color of the avatar.
func WithFgColor(r, g, b, a uint8) optFunc

// WithFgShape sets the shape of the foreground pixels.
func WithFgShape(s [][]int) optFunc

// WithBgShape sets the shape of the background pixels.
func WithBgShape(s [][]int) optFunc

// WithTransparency sets the option to have the background show
// through any negative space in shaped foreground pixels.
func WithTransparency() optFunc

License

This project is open-source under the MIT License.

Contributing

Contributions are welcome! Feel free to open a pull request or create an issue.

About

A lightweight Go package to generate unique, symmetric identicons based on an input string. Easily integrate with your Go project to create visual avatars for users.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%