Optimize PNG, JPEG, GIF, SVG images with grunt task.
Clone or download
Latest commit 87c79d3 Feb 28, 2018
Permalink
Failed to load latest commit information.
lib Fix error Feb 27, 2018
screenshot remove shadow Mar 18, 2014
tasks Fix error Feb 27, 2018
test Fully refactored Jul 17, 2016
.gitignore update files Jan 26, 2014
.travis.yml Build only master branch Dec 30, 2017
gruntfile.js Fully refactored Jul 17, 2016
license Update license Mar 17, 2017
package-lock.json 4.2.0 Feb 28, 2018
package.json 4.2.0 Feb 28, 2018
readme.md Description and tweaks, drop support v4 Oct 7, 2017

readme.md

grunt-image

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

Build Status NPM version Dependency Status devDependency Status

Install

$ npm install --save-dev grunt-image

Usage

This is an example of gruntfile.js.

module.exports = function (grunt) {
  grunt.initConfig({
    image: {
      static: {
        options: {
          optipng: false,
          pngquant: true,
          zopflipng: true,
          jpegRecompress: false,
          mozjpeg: true,
          guetzli: false,
          gifsicle: true,
          svgo: true
        },
        files: {
          'dist/img.png': 'src/img.png',
          'dist/img.jpg': 'src/img.jpg',
          'dist/img.gif': 'src/img.gif',
          'dist/img.svg': 'src/img.svg'
        }
      },
      dynamic: {
        files: [{
          expand: true,
          cwd: 'src/',
          src: ['**/*.{png,jpg,gif,svg}'],
          dest: 'dist/'
        }]
      }
    }
  });

  grunt.loadNpmTasks('grunt-image');
};

You can configure parameters applied to each optimizers such as following:

options: {
  optipng: ['-i 1', '-strip all', '-fix', '-o7', '-force'],
  pngquant: ['--speed=1', '--force', 256],
  zopflipng: ['-y', '--lossy_8bit', '--lossy_transparent'],
  jpegRecompress: ['--strip', '--quality', 'medium', '--min', 40, '--max', 80],
  mozjpeg: ['-optimize', '-progressive'],
  guetzli: ['--quality', 85],
  gifsicle: ['--optimize'],
  svgo: ['--enable', 'cleanupIDs', '--disable', 'convertColors']
}

Result

grunt-image result

License

MIT © Shogo Sensui