Skip to content

Commit 67b2918

Browse files
authored
Merge pull request #4 from sehrgutesoftware/main
Add Printer.Image() method to print images directly
2 parents a35f3a2 + a70b92f commit 67b2918

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

epson.normal.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package escpos
66

77
import (
88
"fmt"
9+
"image"
910
"os"
1011
"path"
1112
"strings"
@@ -65,19 +66,24 @@ func (p *Printer) AztecViaImage(data string, width, height int) error {
6566
if width < 1 {
6667
width = 500
6768
}
69+
6870
aztecCode, err := aztec.Encode([]byte(data), aztec.DEFAULT_EC_PERCENT, aztec.DEFAULT_LAYERS)
6971
if err != nil {
7072
return fmt.Errorf("failed to encode aztec code: %w", err)
7173
}
7274

73-
// Scale the barcode to 200x200 pixels
7475
aztecCode, err = barcode.Scale(aztecCode, width, height)
7576
if err != nil {
7677
return fmt.Errorf("failed to scale aztec code: %w", err)
7778
}
7879

79-
xL, xH, yL, yH, imgData := printImage(aztecCode)
80-
p.write("\x1dv\x30\x00" + string(append([]byte{xL, xH, yL, yH}, imgData...)))
80+
return p.Image(aztecCode)
81+
}
8182

82-
return nil
83+
// Image prints a raster image
84+
//
85+
// The image must be narrower than the printer's pixel width
86+
func (p *Printer) Image(img image.Image) error {
87+
xL, xH, yL, yH, imgData := printImage(img)
88+
return p.write("\x1dv\x30\x00" + string(append([]byte{xL, xH, yL, yH}, imgData...)))
8389
}

0 commit comments

Comments
 (0)