diff --git a/thumbnailing/i/gif.go b/thumbnailing/i/gif.go index cae8fc24d73d82501dcb72568ec9cc047f762aeb..dbaee1a51fd31e28086b37ff0c16f026fe55b1e9 100644 --- a/thumbnailing/i/gif.go +++ b/thumbnailing/i/gif.go @@ -49,15 +49,6 @@ func (d gifGenerator) GenerateThumbnail(b []byte, contentType string, width int, disposal = g.Disposal[i] } - // if disposal type is 1 (preserve previous frame) we can get artifacts from re-scaling. - // as such, we re-render those frames to disposal type 0 (start with a transparent frame) - // see https://www.w3.org/Graphics/GIF/spec-gif89a.txt - if disposal == 1 { - g.Disposal[i] = 0 - } else { - draw.Draw(frameImg, frameImg.Bounds(), image.Transparent, image.Point{X: 0, Y: 0}, draw.Src) - } - // Copy the frame to a new image and use that draw.Draw(frameImg, frameImg.Bounds(), img, image.Point{X: 0, Y: 0}, draw.Over) @@ -94,6 +85,17 @@ func (d gifGenerator) GenerateThumbnail(b []byte, contentType string, width int, }, nil } + // if disposal type is 0 or 1 (preserve previous frame) we can get artifacts from re-scaling. + // as such, we re-render those frames to disposal type 1 (do not dispose) + // Importantly, we do not clear the previous frame buffer canvas + // see https://www.w3.org/Graphics/GIF/spec-gif89a.txt + // This also applies to frame disposal type 0, https://legacy.imagemagick.org/Usage/anim_basics/#none + if disposal == 1 || disposal == 0 { + g.Disposal[i] = 1 + } else { + draw.Draw(frameImg, frameImg.Bounds(), image.Transparent, image.Point{X: 0, Y: 0}, draw.Src) + } + g.Image[i] = targetImg }