Avatar: Generate Avatars for the web
Avatar is a package that allows you to create avatars for pictures and initials.
You can create square avatars, or round avatars.
Picture:
size := 200
fileBytes, _ := ioutil.ReadFile("./test_data/super_mascot.jpg")
newAvatar, _ := NewAvatarFromPic(fileBytes, &PictureOptions{
Size: size,
})
round, err := newAvatar.Circle()
roundFile, _ := os.Create("./output/round_super_mascot.png")
roundFile.Write(round)
square, err := newAvatar.Square()
squareFile, _ := os.Create("./output/square_super_mascot.png")
roundFile.Write(square)
Initials:
size := 200
newAvatar, err := NewAvatarFromInitials([]byte("John Smith"), &InitialsOptions{
FontPath: "./test_data/Arial.ttf",
Size: size,
NInitials: 2,
TextColor: color.White,
BgColor: color.RGBA{0, 0, 255, 255},
})
square, _ := newAvatar.Square()
squareFile, _ := os.Create("./output/square_john_smith_initials.png")
defer squareFile.Close()
squareFile.Write(square)
round, _ := newAvatar.Circle()
roundFile, _ := os.Create("./output/round_john_smith_initials.png")
defer roundFile.Close()
roundFile.Write(round)
The input for initials can be any text, and the package identifies the best candidates for the initials.
If you give it an email address, it will try to identify the initials in the string preceding the @.
Not specifying NInitials in options would print the whole text as is.
And the font path is required, so maybe it should not be put in InitialsOptions, we'll see what the community thinks.
What you get:
From our original picture:
Our outputs