GulpJS: Compressing Images

Standard

Compressing Images

  • Use gulp-imagemin to minify PNG, JPEG, GIF and SVG images
  • Use optimizationLevel attribute to adjust compression between 0 and 7

Pre Install:

    npm install --save-dev gulp gulp-load-plugins 

Install:

    npm install --save-dev gulp-imagemin 

Code:

    var gulp = require('gulp');
    var $ = require('gulp-load-plugins')({ lazy: true });

    gulp.task('images', function () {

        return gulp
            .src('./src/images/')
            .pipe($.imagemin({ optimizationLevel: 4 }))
            .pipe(gulp.dest('./build/images'));
    });

Execute:

    gulp images
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s