@@ -6,6 +6,7 @@ package escpos
66
77import (
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 ( " \x1d v \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 ("\x1d v\x30 \x00 " + string (append ([]byte {xL , xH , yL , yH }, imgData ... )))
8389}
0 commit comments