-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
59 lines (54 loc) · 934 Bytes
/
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
package main
import (
"encoding/json"
"os"
"strings"
"github.com/fumiama/imgsz"
)
//go:generate go run main.go
const wifvesdir = "./wives/"
const jsonfile = "wife.json"
func main() {
ent, err := os.ReadDir(wifvesdir)
if err != nil {
panic(err)
}
cards := make([]string, 0, len(ent))
for _, en := range ent {
if en.IsDir() {
continue
}
name := en.Name()
fn := wifvesdir + name
f, err := os.Open(fn)
if err != nil {
continue
}
_, format, err := imgsz.DecodeSize(f)
_ = f.Close()
if err != nil {
continue
}
i := strings.LastIndex(name, ".")
if i <= 0 {
continue
}
name = name[:i] + "." + format
nfn := wifvesdir + name
if fn != nfn {
err = os.Rename(fn, nfn)
if err != nil {
continue
}
}
cards = append(cards, name)
}
f, err := os.Create(jsonfile)
if err != nil {
panic(err)
}
err = json.NewEncoder(f).Encode(cards)
if err != nil {
panic(err)
}
}