mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
retain original color palette for resized gifs
This commit is contained in:
parent
66fcba95a0
commit
5e9ceeaaf6
1 changed files with 4 additions and 4 deletions
8
third_party/gifresize/gifresize.go
vendored
8
third_party/gifresize/gifresize.go
vendored
|
@ -23,7 +23,7 @@ package gifresize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"image/color/palette"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
"image/gif"
|
"image/gif"
|
||||||
"io"
|
"io"
|
||||||
|
@ -50,15 +50,15 @@ func Process(w io.Writer, r io.Reader, transform TransformFunc) error {
|
||||||
for index, frame := range im.Image {
|
for index, frame := range im.Image {
|
||||||
bounds := frame.Bounds()
|
bounds := frame.Bounds()
|
||||||
draw.Draw(img, bounds, frame, bounds.Min, draw.Over)
|
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)
|
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()
|
b := img.Bounds()
|
||||||
pm := image.NewPaletted(b, palette.Plan9)
|
pm := image.NewPaletted(b, p)
|
||||||
draw.FloydSteinberg.Draw(pm, b, img, image.ZP)
|
draw.FloydSteinberg.Draw(pm, b, img, image.ZP)
|
||||||
return pm
|
return pm
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue