Please help in compressing image using mozjpeg Node JS Package
prahaladm opened this issue · comments
prahaladm commented
Here is the code that I am trying to run:
var execFile = require('child_process').execFile;
var mozjpeg = require("mozjpeg")
execFile(mozjpeg, ['-outfile', './output.jpg', 'http://www.barth.com/hires/N10_JB07006.jpg'], function (err) {
if(err){
console.log("Error in mozjpeg: "+JSON.stringify(err, null,4));
}
else{
console.log('Image minified! without error');
}
});
Below is the error that I get:
Error in mozjpeg: {
"killed": false,
"code": 1,
"signal": null,
"cmd": "/home/ec2-user/ec2apps/curieAppBackend/node_modules/mozjpeg/vendor/cjpeg -outfile ./output.jpg http://www.barth.com/hires/N10_JB07006.jpg"
}
Could some one please suggest:
- How I could resolve this error ?
- Where is the output.jpg (compressed / minified) file stored / located.
sevaru commented
Hi,
The easiest thing you could do is
- download image
- change your code
var execFile = require('child_process').execFile;
var mozjpeg = require("mozjpeg")
var PATH_TO_YOU_INPUT_FILE = './img.jpeg';
execFile(mozjpeg, ['-outfile', './output.jpg', PATH_TO_YOU_INPUT_FILE], function (err) {
if(err){
console.log("Error in mozjpeg: "+JSON.stringify(err, null,4));
}
else{
console.log('Image minified! without error');
}
});
than you would find file output.jpg
in current directory