diff options
Diffstat (limited to 'modules/avatar')
-rw-r--r-- | modules/avatar/avatar.go | 9 | ||||
-rw-r--r-- | modules/avatar/avatar_test.go | 16 |
2 files changed, 13 insertions, 12 deletions
diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index f4c0655fa9..44b56c26ce 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -9,6 +9,7 @@ import ( "fmt" "image" "image/color/palette" + // Enable PNG support: _ "image/png" "math/rand" @@ -57,11 +58,11 @@ func Prepare(data []byte) (*image.Image, error) { if err != nil { return nil, fmt.Errorf("DecodeConfig: %v", err) } - if imgCfg.Width > setting.AvatarMaxWidth { - return nil, fmt.Errorf("Image width is too large: %d > %d", imgCfg.Width, setting.AvatarMaxWidth) + if imgCfg.Width > setting.Avatar.MaxWidth { + return nil, fmt.Errorf("Image width is too large: %d > %d", imgCfg.Width, setting.Avatar.MaxWidth) } - if imgCfg.Height > setting.AvatarMaxHeight { - return nil, fmt.Errorf("Image height is too large: %d > %d", imgCfg.Height, setting.AvatarMaxHeight) + if imgCfg.Height > setting.Avatar.MaxHeight { + return nil, fmt.Errorf("Image height is too large: %d > %d", imgCfg.Height, setting.Avatar.MaxHeight) } img, _, err := image.Decode(bytes.NewReader(data)) diff --git a/modules/avatar/avatar_test.go b/modules/avatar/avatar_test.go index 662d50fadd..8535605652 100644 --- a/modules/avatar/avatar_test.go +++ b/modules/avatar/avatar_test.go @@ -22,8 +22,8 @@ func Test_RandomImage(t *testing.T) { } func Test_PrepareWithPNG(t *testing.T) { - setting.AvatarMaxWidth = 4096 - setting.AvatarMaxHeight = 4096 + setting.Avatar.MaxWidth = 4096 + setting.Avatar.MaxHeight = 4096 data, err := ioutil.ReadFile("testdata/avatar.png") assert.NoError(t, err) @@ -36,8 +36,8 @@ func Test_PrepareWithPNG(t *testing.T) { } func Test_PrepareWithJPEG(t *testing.T) { - setting.AvatarMaxWidth = 4096 - setting.AvatarMaxHeight = 4096 + setting.Avatar.MaxWidth = 4096 + setting.Avatar.MaxHeight = 4096 data, err := ioutil.ReadFile("testdata/avatar.jpeg") assert.NoError(t, err) @@ -50,15 +50,15 @@ func Test_PrepareWithJPEG(t *testing.T) { } func Test_PrepareWithInvalidImage(t *testing.T) { - setting.AvatarMaxWidth = 5 - setting.AvatarMaxHeight = 5 + setting.Avatar.MaxWidth = 5 + setting.Avatar.MaxHeight = 5 _, err := Prepare([]byte{}) assert.EqualError(t, err, "DecodeConfig: image: unknown format") } func Test_PrepareWithInvalidImageSize(t *testing.T) { - setting.AvatarMaxWidth = 5 - setting.AvatarMaxHeight = 5 + setting.Avatar.MaxWidth = 5 + setting.Avatar.MaxHeight = 5 data, err := ioutil.ReadFile("testdata/avatar.png") assert.NoError(t, err) |