-
Notifications
You must be signed in to change notification settings - Fork 1
/
identicon.go
41 lines (33 loc) · 867 Bytes
/
identicon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* User: [email protected]
* Date: 2023/7/18
* Time: 16:28
*/
package identicon
import "fmt"
var i *Identicon
func init() {
i = New()
}
type Identicon struct {
matrix *Matrix
}
func New() *Identicon {
i := new(Identicon)
i.matrix = NewMatrix()
return i
}
func SaveAvatar(id string, size int, fileName string) error {
return i.saveAvatar(id, size, fileName)
}
func (i *Identicon) saveAvatar(id string, size int, fileName string) (err error) {
matrix, color := i.matrix.GetMatrix(id)
return NewGenerator(matrix, size, color).SaveAvatar(fileName)
}
func GetAvatarDataUri(id string, size int) string {
return i.getAvatarDataUri(id, size)
}
func (i *Identicon) getAvatarDataUri(id string, size int) string {
matrix, color := i.matrix.GetMatrix(id)
return fmt.Sprintf("data:image/png;base64,%s", NewGenerator(matrix, size, color).GetBase64())
}