GolangNote

Golang笔记

推荐几个根据输入字符串随机生成头像的 Golang 库

Permalink

适用场合:当用户注册时,根据用户名或邮箱生成一个头像,作为默认头像。

o1egl/govatar

这个首推 https://github.com/o1egl/govatar

使用也方便

Go: govatar
1
2
img, err := govatar.Generate(govatar.MALE)
img, err := govatar.GenerateForUsername(govatar.MALE, "username")

ShiningRush/avatarbuilder

https://github.com/ShiningRush/avatarbuilder

Go: identicon
1
2
3
4
5
6
7
8
9
ab := avatarbuilder.NewAvatarBuilder("./SourceHanSansSC-Medium.ttf", &calc.SourceHansSansSCMedium{})
ab.SetBackgroundColorHex(colors[1])
ab.SetFrontgroundColor(color.White)
ab.SetFontSize(80)
ab.SetAvatarSize(200, 200)
if err := ab.GenerateImageAndSave("12", "./out.png"); err != nil {
    fmt.Println(err)
    return
}

issue9/identicon

https://github.com/issue9/identicon

Go: identicon
1
2
3
4
5
// 根据用户访问的IP,为其生成一张头像
img, _ := identicon.Make(128, color.NRGBA{},color.NRGBA{}, []byte("192.168.1.1"))
fi, _ := os.Create("/tmp/u1.png")
png.Encode(fi, img)
fi.Close()

其它推荐

本文网址: https://golangnote.com/topic/274.html 转摘请注明来源

Related articles

Golang 把cookie 字符串解析为cookie 结构

在做爬虫时有时候会遇到需要带已登录的 cookie 请求,这个时候最简单的方法是在浏览器登录后,在开发者面板找到cookie 字符串,然后拷贝粘贴。这就面临一个问题需要把cookie 字符串解析成Go 语言 cookie 结构体。...

Write a Comment to "推荐几个根据输入字符串随机生成头像的 Golang 库"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.20 Processed in 0ms