Skip to content

Instantly share code, notes, and snippets.

@zreese
Forked from LoyEgor/gulpfile.js
Last active April 16, 2018 18:38
Show Gist options
  • Save zreese/619383a80903b850d933e4c7aa171072 to your computer and use it in GitHub Desktop.
Save zreese/619383a80903b850d933e4c7aa171072 to your computer and use it in GitHub Desktop.
best image compression settings (gulp-imagemin)
// install
// npm i gulp-imagemin imagemin-jpeg-recompress imagemin-pngquant imagemin-zopfli imagemin-mozjpeg -f
var imagemin = require('gulp-imagemin');
var imageminPngquant = require('imagemin-pngquant');
var imageminZopfli = require('imagemin-zopfli');
var imageminMozjpeg = require('imagemin-mozjpeg'); //need to run 'brew install libpng'
var imageminJpegRecompress = require('imagemin-jpeg-recompress');
gulp.task('imagemin', function() {
return gulp.src(['src/**/*.{png,jpg}'])
.pipe(imagemin([
//png
imageminPngquant({
speed: 1,
quality: 98 //lossy settings
}),
imageminZopfli({
more: true
}),
//jpg lossless
imagemin.jpegtran({
progressive: true
}),
imageminJpegRecompress({
loops:6,
min: 40,
max: 85,
quality:'low'
}),
//jpg very light lossy, use vs jpegtran
imageminMozjpeg({
quality: 90
})
]))
.pipe(gulp.dest('dist'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment