Skip to content

Commit a8fac8f

Browse files
committed
Fix background transparent
1 parent 2a56c66 commit a8fac8f

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cmd/gosgif/main.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package main
22

33
import (
44
"fmt"
5+
"image"
6+
"image/color/palette"
7+
"image/draw"
58
"image/gif"
69
"io"
710
"log"
@@ -57,11 +60,23 @@ func main() {
5760
fmt.Printf("\x1b[%dA", lines)
5861
fmt.Print("\x1b[s")
5962
}
63+
64+
var back draw.Image
65+
if g.BackgroundIndex != 0 {
66+
back = image.NewPaletted(g.Image[0].Bounds(), palette.WebSafe)
67+
}
68+
6069
for {
6170
t := time.Now()
6271
for j := 0; j < len(g.Image); j++ {
6372
fmt.Print("\x1b[u")
64-
err = enc.Encode(g.Image[j])
73+
if back != nil {
74+
draw.Draw(back, back.Bounds(), &image.Uniform{g.Image[j].Palette[g.BackgroundIndex]}, image.Pt(0, 0), draw.Src)
75+
draw.Draw(back, back.Bounds(), g.Image[j], image.Pt(0, 0), draw.Src)
76+
err = enc.Encode(back)
77+
} else {
78+
err = enc.Encode(g.Image[j])
79+
}
6580
if err != nil {
6681
return
6782
}

0 commit comments

Comments
 (0)