Converting from type: 'image/png' to ZPL in NodeJs

前端 未结 1 1484
小蘑菇
小蘑菇 2021-01-23 09:01

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://la

相关标签:
1条回答
  • 2021-01-23 09:36

    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`;
    
    0 讨论(0)
提交回复
热议问题