Transparency = Black

This commit is contained in:
Neale Pickett 2023-09-02 17:19:51 -06:00
parent 497d33e78a
commit 223d32722d
1 changed files with 7 additions and 4 deletions

View File

@ -112,19 +112,22 @@ func handleUpload(w http.ResponseWriter, r *http.Request) {
return
}
// Implement GIF disposal modes
// Normally you woud want to use draw.Src instead of draw.Over for the first of each of these.
// But in this particular application, we want transparency to become black.
draw.Src.Draw(dst, imgRect, image.Black, image.Point{})
switch inputGif.Disposal[i] {
case gif.DisposalNone:
draw.Src.Draw(dst, previousImg.Rect, previousImg, image.Point{})
draw.Over.Draw(dst, previousImg.Rect, previousImg, image.Point{})
draw.Over.Draw(dst, img.Rect, img, img.Rect.Min)
undisposedImg = dst
case gif.DisposalBackground:
draw.Src.Draw(dst, backgroundImg.Rect, backgroundImg, image.Point{})
draw.Over.Draw(dst, backgroundImg.Rect, backgroundImg, image.Point{})
draw.Over.Draw(dst, img.Rect, img, img.Rect.Min)
case gif.DisposalPrevious:
draw.Src.Draw(dst, undisposedImg.Rect, undisposedImg, image.Point{})
draw.Over.Draw(dst, undisposedImg.Rect, undisposedImg, image.Point{})
draw.Over.Draw(dst, img.Rect, img, img.Rect.Min)
default:
draw.Src.Draw(dst, img.Rect, image.Black, image.Point{})
draw.Over.Draw(dst, img.Rect, img, img.Rect.Min)
}