grunt-img

Grunt task to optimize png and jpg images with optipng & jpegtran

grunt-img

Grunt task to optimize PNG and JPG images with optipng & jpegtran (jpegtran-turbo on win32).

First, be sure that you have optipng 0.7(or earlier) and jpegtran installed in your system.

You can install with homebrew

brew install optipng jpeg

Debian, Ubuntu and Mint

apt-get install optipng libjpeg libjpeg-progs

Both libraries are easy to find for RPM distributions too.

Don't worry because both libraries are included.

Install this task next to your project's grunt.js gruntfile with:

npm install grunt-img

Then add the line bellow to your project's grunt.js gruntfile:

grunt.loadNpmTasks('grunt-img');

Questions? Take a look at this stream

Grunt provide a simple way to config its tasks, grunt-img follow the same principle:

grunt.initConfig({
    img: {
 
        // using only dirs with output path 
        task1: {
            src: 'public/src',
            dest: 'public/img'
        },
 
        // recursive extension filter with output path 
        task2: {
            src: ['public/src/**/*.png'],
            dest: 'public/img'
        },
 
        // file by file with output path 
        task3: {
            src: ['public/src/logo.png','public/src/social.jpg'],
            dest: 'public/img'
        },
 
        // single path to optimize and replace all images 
        task4: {
            src: 'public/img'
        },
 
        // file by file to optimize and replace 
        task5: {
            src: ['public/img/concert.jpg, public/img/halestorm.png']
        },
 
        // filter extension to optimize and replace 
        task6: {
            src: ['public/img/*.png']
        }
    }
});

MIT License (c) Helder Santana