I need to convert a ZPL file into an image. I already use the labelary web service, but I need a solution that is less dependent on an external application.
I am proceeding in the following way. I'm getting the base64 encoded part: eJzs281u4zYQAGAKLMCewmsPhfgaPWipPtIeVUC1GPiQYx6hr9FDgdL....rest of the code (Z64 encoded), which would be the image of the ZPL file, and I'm trying to convert this to a png image. I tried using the code below, but I get this error: Error: Could not find MIME for Buffer
const fs = require('fs');
var base64Img = require('base64-img');
var Jimp = require('jimp');
try{
var data = fs.readFileSync('./test.zpl', 'base64')
} catch (err) {
console.log(err);
}
var buffer = Buffer.from(data, 'base64');
Jimp.read(buffer).then(res => {
return res
.quality(50)
.rotate(90)
.resize(250,250)
.writeAsync('out.png');
}).catch(err => {
console.log(err);
});
I tried using this method too, but it generates a png image, but it cannot be processed by the image viewer.
const fs = require('fs');
var base64Img = require('base64-img');
try{
var data = fs.readFileSync('./test.zpl', 'base64')
} catch (err) {
console.log(err);
}
var buffer = Buffer.from(data, 'base64');
fs.writeFileSync("./out.png", buffer);
Grateful.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment