Skip to content

😍 Advanced, extendable SVG avatar generator for Go.

License

Notifications You must be signed in to change notification settings

go-universal/avatar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Avatar

GitHub Tag Go Reference License Go Report Card Contributors Issues

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
Letter Sticker Male Female

Installation

To install Avatar, use go get:

go get github.com/go-universal/avatar

Usage

Creating a Text 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)
    }
}

Creating a Sticker Avatar

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)
    }
}

Creating a Person Avatar

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)
    }
}

Extending

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:

  • Start by editing the template.ai file.
  • Save your design as an SVG.
  • Extract the relevant parts (e.g., shapes, hair, accessories) and integrate them into the avatar package.

Each SVG shape must include placeholders to enable dynamic replacement of colors in the final rendering.

Template Variables for Custom Palettes

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 color

These variables allow your avatar elements to adapt to different themes and palettes dynamically.

License

This project is licensed under the ISC License. See the LICENSE file for details.

About

😍 Advanced, extendable SVG avatar generator for Go.

Topics

Resources

License

Stars

Watchers

Forks

Languages