I'm just experimenting with Gulp to simply optimize images. I find that imagemin-jpeg-recompress reduces JPGs more than the default optimizer that comes with gulp-imagemin. I'm wondering if there is a way to use gulp-imagemin
but swap out the jpegtran
plugin for the the imagemin-jpeg-recompress
.
I can't seem to find any detailed docs as to how this might work together.
I'm going to answer my own question. I could be wrong but it seems it's an easy process. Simply require
the plugin (in this case, I want to use imagemin-jpeg-recompress
plugin). Then specify the plugin to use within imagemin
via the use
property of imagemin
. I believe this will override the bundled jpegtran
optimizer that comes with imagemin
.
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var imageminJpegRecompress = require('imagemin-jpeg-recompress');
gulp.task('optimize', function () {
return gulp.src('src/images/*')
.pipe(imagemin({
use:[imageminJpegRecompress({
loops:4,
min: 50,
max: 95,
quality:'high'
})]
}))
});