From 5e9ceeaaf6bd7e44d5818d1a9bafdf51ef571e2e Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 18 May 2015 15:37:28 -0700 Subject: [PATCH] retain original color palette for resized gifs --- third_party/gifresize/gifresize.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/third_party/gifresize/gifresize.go b/third_party/gifresize/gifresize.go index cc89d0b..067b57d 100644 --- a/third_party/gifresize/gifresize.go +++ b/third_party/gifresize/gifresize.go @@ -23,7 +23,7 @@ package gifresize import ( "image" - "image/color/palette" + "image/color" "image/draw" "image/gif" "io" @@ -50,15 +50,15 @@ func Process(w io.Writer, r io.Reader, transform TransformFunc) error { for index, frame := range im.Image { bounds := frame.Bounds() draw.Draw(img, bounds, frame, bounds.Min, draw.Over) - im.Image[index] = imageToPaletted(transform(img)) + im.Image[index] = imageToPaletted(transform(img), frame.Palette) } return gif.EncodeAll(w, im) } -func imageToPaletted(img image.Image) *image.Paletted { +func imageToPaletted(img image.Image, p color.Palette) *image.Paletted { b := img.Bounds() - pm := image.NewPaletted(b, palette.Plan9) + pm := image.NewPaletted(b, p) draw.FloydSteinberg.Draw(pm, b, img, image.ZP) return pm }