-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (47 loc) · 1.8 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
package main
import(
"fmt"
"strings"
"os"
"strconv"
"os/exec"
)
func execute(command string) string {
out, err := exec.Command("bash", "-c", command).Output()
if err != nil {}
output := string(out[:])
return output
}
func generateColorblindType(colorblindType string, filesSplited []string){
simpleType := strings.Split(colorblindType, "")
var outputFiles string
filesSplitedLen := len(filesSplited) - 3
for i := 0; i < filesSplitedLen; i++{
file := filesSplited[i]
iString := strconv.Itoa(i)
execute("daltonize -s -t=" + simpleType[0] + " tmpColorblinder/" + file + " tmpColorblinder/" + colorblindType + "/" + iString + ".png")
outputFiles += "tmpColorblinder/" + colorblindType + "/" + iString + ".png "
fmt.Println(colorblindType, ":", i + 1, "° Page.")
}
execute("img2pdf " + outputFiles + "-o " + colorblindType + ".pdf")
}
func generateDaltonize(filesSplited []string) {
generateColorblindType("deltan", filesSplited)
generateColorblindType("protan", filesSplited)
generateColorblindType("tritan", filesSplited)
}
func main() {
if (len(os.Args) < 2){
panic("Please, specify the PDF file.")
}
execute("[ -d \"tmpColorblinder\" ] && rm -rf tmpColorblinder")
execute("mkdir tmpColorblinder tmpColorblinder/deltan tmpColorblinder/protan tmpColorblinder/tritan")
fmt.Println("Converting PDF to images...")
execute("convert -density 400 \"" + os.Args[1] + "\" -quality 100 \"tmpColorblinder/capture.png\"")
fmt.Println("PDF converted to images.")
files := execute("ls tmpColorblinder")
filesSplited := strings.Fields(files)
generateDaltonize(filesSplited)
execute("rm -rf tmpColorblinder")
fmt.Println("Finish! Let's check the files deltan.pdf, protan.pdf and tritan.pdf")
}