@@ -6,6 +6,7 @@ package escpos
6
6
7
7
import (
8
8
"fmt"
9
+ "image"
9
10
"os"
10
11
"path"
11
12
"strings"
@@ -65,19 +66,24 @@ func (p *Printer) AztecViaImage(data string, width, height int) error {
65
66
if width < 1 {
66
67
width = 500
67
68
}
69
+
68
70
aztecCode , err := aztec .Encode ([]byte (data ), aztec .DEFAULT_EC_PERCENT , aztec .DEFAULT_LAYERS )
69
71
if err != nil {
70
72
return fmt .Errorf ("failed to encode aztec code: %w" , err )
71
73
}
72
74
73
- // Scale the barcode to 200x200 pixels
74
75
aztecCode , err = barcode .Scale (aztecCode , width , height )
75
76
if err != nil {
76
77
return fmt .Errorf ("failed to scale aztec code: %w" , err )
77
78
}
78
79
79
- xL , xH , yL , yH , imgData := printImage (aztecCode )
80
- p . write ( " \x1d v \x30 \x00 " + string ( append ([] byte { xL , xH , yL , yH }, imgData ... )))
80
+ return p . Image (aztecCode )
81
+ }
81
82
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 ("\x1d v\x30 \x00 " + string (append ([]byte {xL , xH , yL , yH }, imgData ... )))
83
89
}
0 commit comments