Skip to content
Snippets Groups Projects
Unverified Commit 486c18f6 authored by Travis Ralston's avatar Travis Ralston Committed by GitHub
Browse files

Merge pull request #295 from Sorunome/soru/fix-gif

fix: Some gifs not thumbnailing correctly
parents d8881dda 82bb3834
No related branches found
No related tags found
No related merge requests found
......@@ -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
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment