gulp lossy image compression does not work

304
June 16, 2017, at 2:26 PM

I try to use gulp-imagemin module with imagemin-mozjpeg plugin to lossely compress image assets. I tried to modelled my gulp pipeline on the lossy-imagemin module (here its simple source code: https://github.com/builden/lossy-imagemin/blob/master/lib/lossy-imagemin.js).

So I have a gulpfile.js like this:

var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var mozjpeg = require('imagemin-mozjpeg');
var lossymin = require('lossymin-imagemin');
gulp.task('imagemin', function() {
    gulp.src('src/img/*')
    .pipe(imagemin({ progressive: true, 
                     use:[pngquant(), 
                     mozjpeg({quality: '70'})],
                     verbose: true}))
    .pipe(gulp.dest('img_imagemin'))
});
gulp.task('lossymin', 
    lossymin('src/img/*','img', 
             { jpgQuality: '70', cache: false },
             function(err) {}
    )
);

And the problem is that the 'lossymin' task based on lossy-imagemin does work correctly (that is, it compresses images really well with about 80% reduction), but my custom task 'imagemin' which is basically the same as the 'lossymin' task (look at the source code of the lossy-imagemin' modules; the link is above) does not work, that is, it almost does not compresses images at all (6.5% reduction).

So the question is: why is it so?

I seriously have no idea, so any help will be much appreciated.

EDIT. I found a partial answer. For some reason gulp-imagemin in version 3.0+ starts to behave differently when joined with imagemin-mozjpeg and imagemin-pngquant. When I switch to older versions of these 3 modules I get good compression like when using lossy-imagemin module.

However it still entirely unclear to me why these new versions behave so strangely.

So summing up, versions:

  • gulp-imagemin 2.4.0
  • imagemin-mozjpeg 5.1.0
  • imagemin-pngquant 4.2.2

works nice and give more than 80% reduction in compression. At the same time versions:

  • gulp-imagemin 3.3.0
  • imagemin-mozjpeg 6.0.0
  • imagemin-pngquant 5.0.1

behave weird and give only 6.5% reduction on the same images and the same settings (quality = 70).

So all of this is very strange.

[I add node as tag, since it seems to be related to some weird interactions between node modules]

READ ALSO
When using the async='true' on my html script tag to load socket.io.js it cause an undefined error for the io object any suggestion?

When using the async='true' on my html script tag to load socket.io.js it cause an undefined error for the io object any suggestion?

When adding async='true' as an inline property to a html script tag to serve my socketio

277
Codeship Basic npm install fails Error: SSL Error: CERT_UNTRUSTED

Codeship Basic npm install fails Error: SSL Error: CERT_UNTRUSTED

I'm having a consistent issue where my Codeship Basic setup step is failing when running npm install:

549
Nodejs: how can undefined variable evaluate to true?

Nodejs: how can undefined variable evaluate to true?

I've searched for this and come up with nothingI must be doing something wrong, but can't work out what

305
How to protect a NodeJS API server used with a React application?

How to protect a NodeJS API server used with a React application?

I have a React front-end that calls REST APIsThe front-end and back-end are hosted on different servers

215