From bdf995c94fb1e1db2ac624c21a95cf3df3e1cbde Mon Sep 17 00:00:00 2001 From: Will Norris Date: Fri, 15 May 2015 16:07:00 -0700 Subject: [PATCH] use new gifresize package on all gif images Fixes #23 --- transform.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/transform.go b/transform.go index 241a38d..0325e74 100644 --- a/transform.go +++ b/transform.go @@ -17,11 +17,12 @@ package imageproxy import ( "bytes" "image" - "image/gif" + _ "image/gif" // register gif format "image/jpeg" "image/png" "github.com/disintegration/imaging" + "willnorris.com/go/imageproxy/third_party/gifresize" ) // default compression quality of resized jpegs @@ -45,21 +46,27 @@ func Transform(img []byte, opt Options) ([]byte, error) { return nil, err } - m = transformImage(m, opt) - - // encode image + // transform and encode image buf := new(bytes.Buffer) switch format { case "gif": - gif.Encode(buf, m, nil) + fn := func(img image.Image) image.Image { + return transformImage(img, opt) + } + err = gifresize.Process(buf, bytes.NewReader(img), fn) + if err != nil { + return nil, err + } case "jpeg": quality := opt.Quality if quality == 0 { quality = defaultQuality } + m = transformImage(m, opt) jpeg.Encode(buf, m, &jpeg.Options{Quality: quality}) case "png": + m = transformImage(m, opt) png.Encode(buf, m) }