-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (61 loc) · 1.72 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
package main
import (
"encoding/binary"
"encoding/hex"
"flag"
"fmt"
"math/rand"
"os"
"path"
"time"
"git.cheetah.cat/cheetah/go-snake-label/lib"
"gopkg.in/gographics/imagick.v2/imagick"
)
var src = rand.New(rand.NewSource(time.Now().UnixNano()))
func RandStringBytesMaskImprSrc(n int) string {
b := make([]byte, (n+1)/2)
if _, err := src.Read(b); err != nil {
panic(err)
}
return hex.EncodeToString(b)[:n]
}
func tempPNGPath() string {
return path.Join(os.TempDir(), fmt.Sprintf(RandStringBytesMaskImprSrc(16), ".png"))
}
// sudo apt-get install libmagickwand-dev
func main() {
imagick.Initialize()
defer imagick.Terminate()
inputFile := flag.String("input", "", "input filename")
outputFile := flag.String("output", "", "output filename")
modeSelect := flag.String("mode", "dhlprivat", "mode select (dhlprivat, dhlprivatint)")
flag.Parse()
if len(*inputFile) < 3 {
panic("invalid input file")
}
if len(*outputFile) == 0 {
panic("invalid output file")
}
tempFileName := tempPNGPath()
defer os.Remove(tempFileName)
outputFileName := *outputFile
outputSTDOUT := false
if outputFileName == "-" || outputFileName == "/dev/stdout" {
outputSTDOUT = true
outputFileName = tempPNGPath()
defer os.Remove(outputFileName)
}
switch *modeSelect {
case "dhlprivat":
// scale: 4, // optional, defaults to 4 (288dpi) -- 4.1666 for 300dpi
lib.ConvertPDF2PNG(*inputFile, tempFileName, 288, 90)
lib.DHLPrivat(tempFileName, outputFileName)
case "dhlprivatint":
lib.ConvertPDF2PNG(*inputFile, tempFileName, 288, 90)
lib.DHLPrivatInternational(tempFileName, outputFileName)
}
if outputSTDOUT {
outputBytes, _ := os.ReadFile(outputFileName)
binary.Write(os.Stdout, binary.LittleEndian, outputBytes)
}
}