-
-
Notifications
You must be signed in to change notification settings - Fork 141
/
iconize.go
46 lines (39 loc) · 849 Bytes
/
iconize.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
//go:build ignore
// generates .ico files from images.
package main
import (
"flag"
"os"
"os/exec"
"path/filepath"
"strings"
)
const iconExt = ".ico"
var dir string
func init() {
flag.StringVar(&dir, "d", "icon", "The directory of image files.")
flag.Parse()
}
func main() {
files, err := os.ReadDir(dir)
if err != nil {
println(err.Error())
os.Exit(1)
}
for _, f := range files {
if f.IsDir() {
continue
}
path := filepath.Join(dir, f.Name())
ext := filepath.Ext(path)
if ext == iconExt {
continue
}
output := strings.TrimSuffix(path, ext) + iconExt
res, err := exec.Command(".deps/convert.exe", "-background", "none", path,
"-define", "icon:auto-resize=256,192,128,96,64,48,40,32,24,20,16", "-compress", "zip", output).CombinedOutput()
if err != nil {
println(err.Error(), string(res))
}
}
}