-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (71 loc) · 1.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"bytes"
"image/png"
"io/ioutil"
"os"
"strings"
"github.com/toteki/wiz"
"golang.org/x/image/webp"
)
func main() {
wiz.MkDir("./output")
/////////////////////////////////
files, err := ioutil.ReadDir("./input")
if err != nil {
wiz.Red(err.Error())
return
}
s := []string{}
for _, file := range files {
if strings.HasSuffix(file.Name(), ".webp") {
s = append(s, file.Name())
}
}
wiz.Green(s)
/////////////////////////////////
i := 0
for i < len(s) {
if wiz.SilentPrompt(s[i]) == "" {
nemu := strings.TrimSuffix(s[i], ".webp")
convert(nemu)
i++
} else {
return
}
}
}
func convert(f string) {
b, err := wiz.ReadFile("./input/" + f + ".webp")
if err != nil {
wiz.Red(err)
return
}
i, err := webp.Decode(bytes.NewReader(b))
if err != nil {
wiz.Red(err)
return
}
////////////
_, chk := wiz.ReadFile("./output/" + f + ".png")
if chk == nil {
wiz.Red("Already exists")
return
}
fi, err := os.Create("./output/" + f + ".png")
if err != nil {
wiz.Red(err)
return
}
defer fi.Close()
err = png.Encode(fi, i)
if err != nil {
wiz.Red(err)
return
}
err = wiz.DeleteFile("./input/" + f + ".webp")
if err != nil {
wiz.Purple(err)
return
}
}