-
Notifications
You must be signed in to change notification settings - Fork 6
/
png2escpos.go
74 lines (55 loc) · 1.87 KB
/
png2escpos.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 (
"fmt"
"os"
"github.com/mugli/png2escpos/escpos"
)
func main() {
if len(os.Args) < 2 {
showHelp()
}
if os.Args[1] == "help" || os.Args[1] == "--help" || os.Args[1] == "-h" {
showHelp()
}
imgFile := os.Args[1]
err := escpos.PrintImage(imgFile, os.Stdout)
if err != nil {
fmt.Println("Error printing image: %v", err)
os.Exit(1)
}
}
func showHelp() {
help := `
▄▄▄▄▄▄▄ ▄▄ ▄ ▄▄▄▄▄▄▄
█ ▄▄▄ █ ▄▀▄ █ █ ▄▄▄ █
█ ███ █ █▄▄▀ █ ███ █
█▄▄▄▄▄█ ▄ ▄ ▄ █▄▄▄▄▄█
▄▄▄▄ ▄ ▄▀█ ▄ ▄▄▄ ▄
▀▄█ ▀▀▄▀ ▀▀ █ ▄▄▀█▄▄█
███▄▄▄▄▄█ █▄▀ ▄█ ▀ ▀
▄▄▄▄▄▄▄ ▀▄▄ ▀▄▄█▄▄▀
█ ▄▄▄ █ ▄▀█▀█ ▀ █ ▀
█ ███ █ █▄█▄ █▄▀ ▀
█▄▄▄▄▄█ █▄▄██▄▀█▄ ▄ ▀
------
Usage:
Quickly converts PNG files to ESC/POS format and write to stdout,
for printing on Epson thermal point-of-sale printers.
This utility removes transparency from image, makes it grayscale
and then encodes in ESC/POS format.
./png2escpos <filename.png>:
Binary output in ESC/POS format will be written directly to stdout.
You can pipe this output directly into an Epson compatible thermal printer with:
Linux: ./png2escpos <file.png> > /dev/usb/lp0
macOS: ./png2escpos <file.png> | lpr -P NAME_OF_PRINTER
Or, if you have a network printer listening at 192.168.1.100:9100
you can use socat to forward from stdin to network like this:
Linux: ./png2escpos <file.png> | socat STDIN TCP4:192.168.1.100:9100
macOS: ./png2escpos <file.png> | socat STDIN TCP4:192.168.1.100:9100
Other commands:
help, --help, -h:
Shows this message
`
fmt.Println(help)
os.Exit(0)
}