Skip to content

Commit 835c64f

Browse files
committed
gif loop count
1 parent 81bff74 commit 835c64f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

cmd/pic2ascii/main.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func main() {
3131
h := flag.Uint("h", 0, "resize height")
3232
o := flag.String("o", "", "output file")
3333
t := flag.String("t", "", "file type")
34+
m := flag.Int("m", -1, "Gif max loop count")
3435
prefix := flag.String("p", "", "prefix")
3536
suffix := flag.String("s", "\n", "suffix")
3637
flag.Parse()
@@ -102,26 +103,25 @@ func main() {
102103
return
103104
}
104105

106+
dds := []string{}
107+
sg := pic2ascii.SliceGIF(img)
108+
for _, v := range sg {
109+
dds = append(dds, fmt.Sprintln(toAscii(v)))
110+
}
111+
105112
if *o == "" {
106113
if img.LoopCount == 0 {
107-
img.LoopCount = -1
114+
img.LoopCount = *m
108115
}
109116

110-
sg := pic2ascii.SliceGIF(img)
111117
for i := 0; i != img.LoopCount; i++ {
112-
for k, v := range sg {
118+
for k, v := range dds {
113119
time.Sleep(time.Duration(img.Delay[k]) * time.Second / 100)
114-
dd := toAscii(v)
115-
fmt.Println(dd)
120+
fmt.Println(v)
116121
}
117122
}
118123
} else {
119-
dd := ""
120-
sg := pic2ascii.SliceGIF(img)
121-
for _, v := range sg {
122-
dd += fmt.Sprintln(toAscii(v))
123-
}
124-
ioutil.WriteFile(*o, []byte(dd), 0666)
124+
ioutil.WriteFile(*o, []byte(strings.Join(dds, "\n")), 0666)
125125
}
126126

127127
default:

0 commit comments

Comments
 (0)