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

npm install grunt-img
7 downloads in the last day
418 downloads in the last week
2 175 downloads in the last month


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

Getting Started

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

for Mac users

You can install with homebrew

brew install optipng jpeg

for Linux users

Debian, Ubuntu and Mint

apt-get install optipng libjpeg libjpeg-progs

Both libraries are easy to find for RPM distributions too.

for Windows users

Don't worry because both libraries are included.

Setup task grunt-img with grunt.js

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:


Questions? Take a look at this stream

How to config

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

    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


npm loves you