diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-20 01:10:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-20 01:10:41 +0800 |
commit | a8fd76557b9c878d5765382c02ee15202d1857f9 (patch) | |
tree | a3863134791b2cb70eae3a48dcb7013d9285d891 /modules/avatar/avatar.go | |
parent | 38347aa16f7cfb32bb984ade4518bd311d0aff12 (diff) | |
download | gitea-a8fd76557b9c878d5765382c02ee15202d1857f9.tar.gz gitea-a8fd76557b9c878d5765382c02ee15202d1857f9.zip |
Better builtin avatar generator (#17707)
This PR fixes the builtin avatar generator.
1. The random background color makes some images very dirty. So now we only use white background for avatars.
2. We use left-right mirror avatars to satisfy #14799
3. Fix a small padding error in the algorithm
Diffstat (limited to 'modules/avatar/avatar.go')
-rw-r--r-- | modules/avatar/avatar.go | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index 5411a90796..6ca75ed90f 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -8,16 +8,15 @@ import ( "bytes" "fmt" "image" - "image/color/palette" + "image/color" _ "image/gif" // for processing gif images _ "image/jpeg" // for processing jpeg images _ "image/png" // for processing png images + "code.gitea.io/gitea/modules/avatar/identicon" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" - "github.com/issue9/identicon" "github.com/nfnt/resize" "github.com/oliamb/cutter" ) @@ -28,20 +27,8 @@ const AvatarSize = 290 // RandomImageSize generates and returns a random avatar image unique to input data // in custom size (height and width). func RandomImageSize(size int, data []byte) (image.Image, error) { - randExtent := len(palette.WebSafe) - 32 - integer, err := util.RandomInt(int64(randExtent)) - if err != nil { - return nil, fmt.Errorf("util.RandomInt: %v", err) - } - colorIndex := int(integer) - backColorIndex := colorIndex - 1 - if backColorIndex < 0 { - backColorIndex = randExtent - 1 - } - - // Define size, background, and forecolor - imgMaker, err := identicon.New(size, - palette.WebSafe[backColorIndex], palette.WebSafe[colorIndex:colorIndex+32]...) + // we use white as background, and use dark colors to draw blocks + imgMaker, err := identicon.New(size, color.White, identicon.DarkColors...) if err != nil { return nil, fmt.Errorf("identicon.New: %v", err) } |