By Muhammad Saim
User avatars help create a recognizable identity in web apps, social platforms, and online communities. Instead of relying on uploaded images, identicons (automatically generated avatars based on input data) offer a unique, visually distinct way to represent users.
🚀 GoAvatar is an open-source Go package I created to generate unique, symmetric identicons from any input string (such as usernames or email addresses).
Identicons are perfect for applications that need quick, automatically generated profile images while maintaining uniqueness and consistency.
✨ Features
✅ Deterministic Identicons – The same input always generates the same avatar.
✅ Symmetric Designs – The generated icons are mirrored for a clean, balanced look.
✅ Customizable Sizes – Easily adjust the avatar size to fit your app's UI.
✅ Fast & Lightweight – Minimal dependencies for quick generation.
📦 Installation
To install GoAvatar in your project, run:
go get github.com/MuhammadSaim/goavatar
Then, import the package:
import "github.com/MuhammadSaim/goavatar"
🚀 Usage Example
Generating an identicon and saving it as an image is simple:
package main
import (
"github.com/MuhammadSaim/goavatar"
"image/png"
"os"
)
func main() {
// Generate the avatar with a custom foreground and background color
options := goavatar.Options{
Width: 128, // Set custom image width (default is 256)
Height: 128, // Set custom image height (default is 256)
BgColor: color.RGBA{170, 120, 10, 255}, // Change background color (default is light gray)
FgColor: color.RGBA{255, 255, 255, 255}, // Change foreground color (default is extracted from hash)
}
avatar := goavatar.Make("EchoFrost7", options)
// Generates an avatar with a brownish background and white foreground, saving it as avatar.png
file, err := os.Create("avatar.png")
if err != nil {
panic(err)
}
defer file.Close()
png.Encode(file, avatar)
}
🎨 The above code generates an identicon for "exampleUsername" at 128x128 pixels and saves it as "avatar.png".
🔍 Sample Identicons
Here are a few identicons generated with GoAvatar:
"QuantumNomad42"
"EchoFrost7"
"NebulaTide19"
Here are some unique identicons generated using GoAvatar:
![]() |
![]() |
![]() |
---|---|---|
QuantumNomad42 | EchoFrost7 | NebulaTide19 |
Every identicon is unique to the input string, making them perfect for user profiles, forums, and more!
🔗 Get Involved
GoAvatar is open-source! Contributions, issues, and feedback are welcome. If you find it useful, give it a ⭐ on GitHub and share it with fellow developers.
🔗 GitHub Repo: github.com/MuhammadSaim/goavatar
Happy coding! 🚀
Top comments (0)