Initials avatar generation for Go.
Generate a 100x100px 'A'-initial avatar:
img, err := initials.Draw(100, 'A', nil)The third parameter options *Options can be used for customization:
type Options struct {
Font *opentype.Font
Palette []color.Color
LetterColor color.Color
PaletteKey string
FontSize int
}Using a custom palette:
img, err := initials.Draw(100, []rune{'A'}, &initials.Options{
Palette: []color.Color{
color.RGBA{255, 0, 0, 255},
color.RGBA{0, 255, 0, 255},
color.RGBA{0, 0, 255, 255},
},
})https://godoc.org/github.com/weavatar/initials
package main
import (
"image/png"
"log"
"os"
"unicode/utf8"
"github.com/weavatar/initials"
)
var names = []string{
"Alice",
"Bob",
"Carol",
"Dave",
"Eve",
"Frank",
"Gloria",
"Henry",
"Isabella",
"James",
"Жозефина",
"Ярослав",
}
func main() {
for _, name := range names {
firstLetter, _ := utf8.DecodeRuneInString(name)
img, err := initials.Draw(75, []rune{firstLetter}, nil)
if err != nil {
log.Fatal(err)
}
file, err := os.Create(name + ".png")
if err != nil {
log.Fatal(err)
}
err = png.Encode(file, img)
if err != nil {
log.Fatal(err)
}
}
}The package "initials" is distributed under the terms of the MIT license.
The Roboto-Medium font is distributed under the terms of the Apache License v2.0.
See LICENSE.