From 6488ee12be3c8112d30bb490189618261886088e Mon Sep 17 00:00:00 2001 From: Dennis Chen Date: Thu, 21 Jul 2016 02:31:14 -0500 Subject: [PATCH] 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 --- models/user.go | 5 ++--- modules/avatar/avatar.go | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/models/user.go b/models/user.go index 6c95542de..e8e79f247 100644 --- a/models/user.go +++ b/models/user.go @@ -12,7 +12,6 @@ import ( "errors" "fmt" "image" - "image/jpeg" _ "image/jpeg" "image/png" "os" @@ -222,7 +221,7 @@ func (u *User) GenerateRandomAvatar() error { } 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) } @@ -321,7 +320,7 @@ func (u *User) UploadAvatar(data []byte) error { 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() defer sessionRelease(sess) diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index e9d0c1282..a8c3826d1 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -14,7 +14,7 @@ import ( "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 // 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 // in default size (height and width). func RandomImage(data []byte) (image.Image, error) { - return RandomImageSize(_RANDOM_AVATAR_SIZE, data) + return RandomImageSize(AVATAR_SIZE, data) }