From 10335c9111572ae06ae9d43e847a77394835442f Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 2 Mar 2018 22:30:39 +0100 Subject: [PATCH] Use standard image decoder --- pages/upload/upload.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pages/upload/upload.go b/pages/upload/upload.go index e6ea78fd..c41ecc47 100644 --- a/pages/upload/upload.go +++ b/pages/upload/upload.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "image" - "io" "net/http" "github.com/aerogo/aero" @@ -25,19 +24,14 @@ func Avatar(ctx *aero.Context) string { return ctx.Error(http.StatusInternalServerError, "Reading request body failed", err) } - format, err := guessImageFormat(bytes.NewReader(data)) + // Decode + img, format, err := image.Decode(bytes.NewReader(data)) if err != nil { - return ctx.Error(http.StatusBadRequest, "Could not determine image file type", err) + return ctx.Error(http.StatusBadRequest, "Invalid image format", err) } - fmt.Println("Avatar received!", len(data), format, user.Nick) + fmt.Println("Avatar received!", len(data), format, img.Bounds().Dx(), img.Bounds().Dy(), user.Nick) // ioutil.WriteFile("avatar") return "ok" } - -// Guess image format from gif/jpeg/png/webp -func guessImageFormat(r io.Reader) (format string, err error) { - _, format, err = image.DecodeConfig(r) - return format, err -}