-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
49 lines (45 loc) · 1.11 KB
/
utils.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
package main
import (
"gopkg.in/cheggaaa/pb.v1"
"log"
"path/filepath"
"strconv"
"strings"
)
// A worker pulls jobs off the queue and calls the processing functions for each
func worker(queue <-chan string, failures chan<- string, bar *pb.ProgressBar) {
defer wg.Done()
for img := range queue {
err := processImg(img)
if err != nil {
log.Println(err)
failures <- img
}
bar.Increment()
}
}
// The input is in the format "2109 2743 +312 +274"
func parseTrim(input string) (width, height, x, y int) {
params := strings.Fields(input)
width, err := strconv.Atoi(params[0])
if err != nil {
log.Println("Failed to parse string: ", err)
}
height, err = strconv.Atoi(params[1])
if err != nil {
log.Println("Failed to parse string: ", err)
}
x, err = strconv.Atoi(params[2])
if err != nil {
log.Println("Failed to parse string: ", err)
}
y, err = strconv.Atoi(params[3])
if err != nil {
log.Println("Failed to parse string: ", err)
}
return
}
// Given an input file path, what should the output file path be?
func getOutPath(in string) string {
return filepath.Join(outDir, filepath.Base(in))
}