summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-13 16:43:43 -0500
committerUnknwon <u@gogs.io>2015-11-13 16:43:43 -0500
commit1559bd58e7dee6927d31e1aaf1b6ebfc0ffd59dc (patch)
tree1051e333cd223539788306aa169899b8c332d69a /models/user.go
parent6a664e88c77f1ddd9c5bff4898e21a8271a5da9a (diff)
downloadgitea-1559bd58e7dee6927d31e1aaf1b6ebfc0ffd59dc.tar.gz
gitea-1559bd58e7dee6927d31e1aaf1b6ebfc0ffd59dc.zip
save custom avatar as PNG
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/models/user.go b/models/user.go
index 4f9095ed1f..628a50f720 100644
--- a/models/user.go
+++ b/models/user.go
@@ -14,6 +14,7 @@ import (
"image"
"image/jpeg"
_ "image/jpeg"
+ "image/png"
"os"
"path"
"path/filepath"
@@ -253,11 +254,9 @@ func (u *User) ValidatePassword(passwd string) bool {
// UploadAvatar saves custom avatar for user.
// FIXME: split uploads to different subdirs in case we have massive users.
func (u *User) UploadAvatar(data []byte) error {
- u.UseCustomAvatar = true
-
img, _, err := image.Decode(bytes.NewReader(data))
if err != nil {
- return err
+ return fmt.Errorf("Decode: %v", err)
}
m := resize.Resize(234, 234, img, resize.NearestNeighbor)
@@ -268,19 +267,20 @@ func (u *User) UploadAvatar(data []byte) error {
return err
}
- if _, err = sess.Id(u.Id).AllCols().Update(u); err != nil {
- return err
+ u.UseCustomAvatar = true
+ if err = updateUser(sess, u); err != nil {
+ return fmt.Errorf("updateUser: %v", err)
}
os.MkdirAll(setting.AvatarUploadPath, os.ModePerm)
fw, err := os.Create(u.CustomAvatarPath())
if err != nil {
- return err
+ return fmt.Errorf("Create: %v", err)
}
defer fw.Close()
- if err = jpeg.Encode(fw, m, nil); err != nil {
- return err
+ if err = png.Encode(fw, m); err != nil {
+ return fmt.Errorf("Encode: %v", err)
}
return sess.Commit()