Skip to content Skip to sidebar Skip to footer

Converting From Type: 'image/png' To Zpl In Nodejs

What I'm doing and trying: I'm trying to convert a screenshot taken from a < div > into ZPL string in NodeJS. Pretty much like http://labelary.com/viewer.html that would take

Solution 1:

Converting a generic image to something usable by ZPL is non-trivial and can't be described in a few lines of pseudo-code. Instead, I've had this code sitting around for a while and your question prompted me to clean it up and make it available:

https://github.com/metafloor/zpl-image

or

npm install zpl-image

Works in both the browser and node.js. In the browser, you pass in an <img> or <canvas> element and get back the rendered image in the Z64 compressed GRF format used by ZPL.

The ZPL to print the image and nothing else to a zebra printer would look like:

// image is a <img> or <canvas>let res = imageToZ64(image);

let zpl = `
^XA^LH0,0^FWN^PON^PMN^LRN
^FO10,10^GFA,${res.length},${res.length},${res.rowlen},${res.z64)
^XZ`;

Post a Comment for "Converting From Type: 'image/png' To Zpl In Nodejs"