robgridley / zebra

PHP ZPL builder, image conversion and a basic client for network-connected Zebra label printers.
MIT License
214 stars 54 forks source link

get encoded image without ^XA and ^XZ #21

Open icyz opened 5 years ago

icyz commented 5 years ago

How can I get only ZPL code without ^XA and ^XZ ? Actually I can trim out those tags, but there is any elegant solution? I've inspected the code but didn't see anything for that.

Thanks

bsprengelmeijer commented 2 years ago

One way to do this is with a workaround:

$decoder = GdDecoder::fromPath($imagePath);
$image   = new Image($decoder);

$bytesPerRow = $image->width();
$byteCount   = $bytesPerRow * $image->height();

$zplImage = "^GFA,$byteCount,$byteCount,$bytesPerRow,{$image->toAscii()}";