imagemin / mozjpeg-bin

mozjpeg bin-wrapper that makes it seamlessly available as a local dependency

Home Page:https://github.com/mozilla/mozjpeg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please help in compressing image using mozjpeg Node JS Package

prahaladm opened this issue · comments

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.

Hi,
The easiest thing you could do is

  1. download image
  2. 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