-
-
Save jleei/c204bccbd65c4a7c6abc11ff72de19c7 to your computer and use it in GitHub Desktop.
best image compression settings (gulp-imagemin)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // install | |
| // npm i gulp-imagemin imagemin-pngquant imagemin-zopfli imagemin-mozjpeg imagemin-giflossy | |
| 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 imageminGiflossy = require('imagemin-giflossy'); | |
| //compress all images | |
| gulp.task('imagemin', function() { | |
| return gulp.src(['app/**/*.{gif,png,jpg}']) | |
| .pipe(imagemin([ | |
| //png | |
| imageminPngquant({ | |
| speed: 1, | |
| quality: 98 //lossy settings | |
| }), | |
| imageminZopfli({ | |
| more: true | |
| }), | |
| //gif | |
| // imagemin.gifsicle({ | |
| // interlaced: true, | |
| // optimizationLevel: 3 | |
| // }), | |
| //gif very light lossy, use only one of gifsicle or Giflossy | |
| imageminGiflossy({ | |
| optimizationLevel: 3, | |
| optimize: 3, //keep-empty: Preserve empty transparent frames | |
| lossy: 2 | |
| }), | |
| //svg | |
| imagemin.svgo({ | |
| plugins: [{ | |
| removeViewBox: false | |
| }] | |
| }), | |
| //jpg lossless | |
| imagemin.jpegtran({ | |
| progressive: true | |
| }), | |
| //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