
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
github.com/go-universal/avatar
avatar
is a Go library for generating customizable avatars. It supports creating avatars for text, stickers, and persons with various customization options.
Letter | Sticker | Male | Female |
---|---|---|---|
To install Avatar, use go get
:
go get github.com/go-universal/avatar
package main
import (
"github.com/go-universal/avatar"
"log"
)
func main() {
factory := avatar.
New().
DefaultPalettes().
CircleShape().
Build()
johnDoe := factory.NewText("John Doe", "")
johnDoe.
RandomizeShape().
RandomizePalette()
err := johnDoe.SaveAs("john_doe.svg")
if err != nil {
log.Fatal(err)
}
}
package main
import (
"github.com/go-universal/avatar"
"log"
)
func main() {
factory := avatar.
New().
DefaultPalettes().
CircleShape().
Build()
star := factory.NewSticker("", "")
star.
RandomizeShape().
RandomizePalette()
err := star.SaveAs("star.svg")
if err != nil {
log.Fatal(err)
}
}
package main
import (
"github.com/go-universal/avatar"
"log"
)
func main() {
factory := avatar.
New().
DefaultAccessories().
DefaultBeards().
SuitDress().
PrescriptionGlasses().
DarkHairColor().
DefaultHairs().
DefaultPalettes().
CircleShape().
WhiteSkin().
Build()
male := factory.NewMale("")
male.
RandomizeShape().
RandomizePalette().
RandomizeSkinColor().
RandomizeHairColor().
RandomizeHair().
RandomizeBeard().
RandomizeDress().
RandomizeEye().
RandomizeEyebrow().
RandomizeMouth().
RandomizeGlasses().
RandomizeAccessory()
err := male.SaveAs("male.svg")
if err != nil {
log.Fatal(err)
}
female := factory.NewFemale("")
female.
RandomizeShape().
RandomizePalette().
RandomizeSkinColor().
RandomizeHairColor().
RandomizeHair().
RandomizeBeard().
RandomizeDress().
RandomizeEye().
RandomizeEyebrow().
RandomizeMouth().
RandomizeGlasses().
RandomizeAccessory()
err := female.SaveAs("female.svg")
if err != nil {
log.Fatal(err)
}
}
Avatar generation in this package is based on modular SVG elements. You can easily customize the existing avatar styles or add new ones using the provided helper methods.
To create or modify styles:
Each SVG shape must include placeholders to enable dynamic replacement of colors in the final rendering.
Use the following template variables in your SVG elements to enable dynamic styling:
{shape}
— Background shape color{skin}
— Base skin tone{skin_shadow}
— Shadowed areas of the skin{hair}
— Hair color{hair_shadow}
— Shadowed areas of the hair{hair_highlight}
— Highlighted areas of the hair{dress}
— Clothing color{dress_shadow}
— Shadowed areas of the clothing{decorator}
— Accessories (e.g., glasses, necklace){text}
— Text and sticker colorThese variables allow your avatar elements to adapt to different themes and palettes dynamically.
This project is licensed under the ISC License. See the LICENSE file for details.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.