node package manager

gulp-image

Optimize PNG, JPG, GIF, SVG images with gulp task.

gulp-image

Optimize PNG, JPEG, GIF, SVG images with gulp task.

$ npm install --save-dev gulp-image

This is an example of gulpfile.js.

const gulp = require('gulp');
const image = require('gulp-image');
 
gulp.task('image', function () {
  gulp.src('./fixtures/*')
    .pipe(image())
    .pipe(gulp.dest('./dest'));
});
 
gulp.task('default', ['image']);

You can pass an object to image() as argument such as following:

gulp.task('image', function () {
  gulp.src('./fixtures/*')
    .pipe(image({
      pngquant: true,
      optipng: false,
      zopflipng: true,
      advpng: true,
      jpegRecompress: false,
      jpegoptim: true,
      mozjpeg: true,
      gifsicle: true,
      svgo: true
    }))
    .pipe(gulp.dest('./dest'));
});

Set false if you don't want to apply.

Optionally you may pass enable and disable options to svgo:

gulp.task('image', function () {
  gulp.src('./fixtures/*')
    .pipe(image({
      svgo: { enable: ["removeRasterImages"], disable: ["removeDoctype"] }
    }))
    .pipe(gulp.dest('./dest'));
});

MIT: http://1000ch.mit-license.org/