Grunt task to optimize PNG and JPG images with optipng & jpegtran.
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']
}
}
});
If you want to use jpegrescan. jpegrescan Script that will further compress the JPEG images that are written by Loren Merritt.
Please specify the path to the jpegrescan.
grunt.initConfig({
jpegtran:
rescan: './jpegrescan'
});
MIT License (c) Helder Santana
- HTML5 Boilerplate node-build-script