Skip to content

Commit

Permalink
Merge pull request #4 from sehrgutesoftware/main
Browse files Browse the repository at this point in the history
Add Printer.Image() method to print images directly
  • Loading branch information
meyskens authored Jul 25, 2024
2 parents a35f3a2 + a70b92f commit 67b2918
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions epson.normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package escpos

import (
"fmt"
"image"
"os"
"path"
"strings"
Expand Down Expand Up @@ -65,19 +66,24 @@ func (p *Printer) AztecViaImage(data string, width, height int) error {
if width < 1 {
width = 500
}

aztecCode, err := aztec.Encode([]byte(data), aztec.DEFAULT_EC_PERCENT, aztec.DEFAULT_LAYERS)
if err != nil {
return fmt.Errorf("failed to encode aztec code: %w", err)
}

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

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

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

0 comments on commit 67b2918

Please sign in to comment.