-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·88 lines (74 loc) · 1.77 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
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"strings"
"time"
"github.com/xfort/RockImage/xgif"
"path/filepath"
)
func main() {
compressGif()
}
func compressGif() {
currentPath, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatalln(err)
}
configFile, err := os.Open(filepath.Join(currentPath, "config.txt"))
if err != nil {
log.Fatalln(err, "无法读取config文件", currentPath)
}
defer configFile.Close()
configReader := bufio.NewReader(configFile)
var fromDirPath string
var outDirPath string
var colorNum string
var maxSize string
var watermarkpath string
for {
lineByte, _, err := configReader.ReadLine()
if err == io.EOF {
break
}
linStr := string(lineByte)
if len(linStr) > 3 || !strings.HasPrefix(linStr, "//") {
itemArray := strings.Split(linStr, "=")
if itemArray != nil && len(itemArray) >= 2 {
switch itemArray[0] {
case "fromDir":
fromDirPath = itemArray[1]
case "outDir":
outDirPath = itemArray[1]
case "colorNum":
colorNum = itemArray[1]
case "maxSize":
maxSize = itemArray[1]
case "watermark":
watermarkpath = itemArray[1]
}
}
}
}
log.Println("读取配置\n", fromDirPath+"\n", outDirPath+"\n", colorNum+"\n", maxSize+"\n", watermarkpath)
if fromDirPath == "" {
log.Fatalln("fromDir 错误")
}
if outDirPath == "" {
log.Fatalln("outDir 错误")
}
if colorNum == "" {
colorNum = "256"
}
gifHandler := &xgif.GifHandler{}
err = gifHandler.WatermarkCompressDir(fromDirPath, outDirPath, watermarkpath, colorNum, maxSize)
if err != nil {
log.Println(err.Error())
}
//xgif.CompressGifDir(fromDirPath, outDirPath, maxSize, colorNum)
fmt.Println("任务结束\n", "文件保存路径="+outDirPath)
time.Sleep(60 * time.Second)
}