0
Fork 0
mirror of https://github.com/willnorris/imageproxy.git synced 2024-12-16 21:56:43 -05:00

use new gifresize package on all gif images

Fixes #23
This commit is contained in:
Will Norris 2015-05-15 16:07:00 -07:00
parent 58bb2e4ce9
commit bdf995c94f

View file

@ -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)
}