Gulp plugin to optimize images using ImageOptim and JPEGmini.
Please note this plugin uses ImageOptim-CLI. Unfortunately currently there is no support for Windows and Linux.
So why ImageOptim-CLI? My personal experience and current benchmarks suggest that ImageOptim and ImageAlpha currently outperform alternatives over lossless and lossy optimizations.
var gulp = require('gulp');
var imageOptim = require('gulp-imageoptim');
gulp.task('images', function() {
return gulp.src('src/images/**/*')
.pipe(imageOptim.optimize())
.pipe(gulp.dest('build/images'));
});
Optimize images using ImageOptim-CLI
To enable JPEGmini support, set the option to true
Type: Boolean
Default: false
Set to false to disable optimize summary in console.
Type: Boolean
Default: true
Batch size
Type: Integer
Default: 100
Yes, however, please note that JPEGmini is a paid-for product. We are using ImageOptim-CLI (ImageOptim and ImageAlpha) without JPEGmini. To use JPEGmini you will need to purchase it.
You may be presented with the following message the first time you run Gulp Imageoptim with the jpegmini flag set to true:
To automate JPEGmini we need to add Terminal.app (or iTerm.app etc) to the 'support for assistive devices' whitelist.
The JPEGmini OS X Apps don't include a command line API, so a real user is simulated by entering synthetic clicks and keyboard commands instead. This requires your permission and is easily set up in System Preferences as shown by these guides.
var gulp = require('gulp');
var imageOptim = require('gulp-imageoptim');
gulp.task('images', function() {
return gulp.src('src/images/**/*')
.pipe(imageOptim.optimize({
jpegmini: true
}))
.pipe(gulp.dest('build/images'));
});
Unfortunately, ImageOptim and ImageAlpha are not available on those platforms yet.