1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-21 12:44:49 -05:00

avatar: make custom and generated avatars equal (#3301)

Sets all avatars to use PNG image format.
Keeps avatars consistent at 290x290px resolution.

Signed-off-by: Dennis Chen <barracks510@gmail.com>
This commit is contained in:
Dennis Chen 2016-07-21 02:31:14 -05:00 committed by 无闻
parent c2fb01a257
commit 6488ee12be
2 changed files with 4 additions and 5 deletions

View file

@ -12,7 +12,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"image" "image"
"image/jpeg"
_ "image/jpeg" _ "image/jpeg"
"image/png" "image/png"
"os" "os"
@ -222,7 +221,7 @@ func (u *User) GenerateRandomAvatar() error {
} }
defer fw.Close() defer fw.Close()
if err = jpeg.Encode(fw, img, nil); err != nil { if err = png.Encode(fw, img); err != nil {
return fmt.Errorf("Encode: %v", err) return fmt.Errorf("Encode: %v", err)
} }
@ -321,7 +320,7 @@ func (u *User) UploadAvatar(data []byte) error {
return fmt.Errorf("Decode: %v", err) return fmt.Errorf("Decode: %v", err)
} }
m := resize.Resize(290, 290, img, resize.NearestNeighbor) m := resize.Resize(avatar.AVATAR_SIZE, avatar.AVATAR_SIZE, img, resize.NearestNeighbor)
sess := x.NewSession() sess := x.NewSession()
defer sessionRelease(sess) defer sessionRelease(sess)

View file

@ -14,7 +14,7 @@ import (
"github.com/issue9/identicon" "github.com/issue9/identicon"
) )
const _RANDOM_AVATAR_SIZE = 200 const AVATAR_SIZE = 290
// RandomImage generates and returns a random avatar image unique to input data // RandomImage generates and returns a random avatar image unique to input data
// in custom size (height and width). // in custom size (height and width).
@ -39,5 +39,5 @@ func RandomImageSize(size int, data []byte) (image.Image, error) {
// RandomImage generates and returns a random avatar image unique to input data // RandomImage generates and returns a random avatar image unique to input data
// in default size (height and width). // in default size (height and width).
func RandomImage(data []byte) (image.Image, error) { func RandomImage(data []byte) (image.Image, error) {
return RandomImageSize(_RANDOM_AVATAR_SIZE, data) return RandomImageSize(AVATAR_SIZE, data)
} }