I am trying to lossless optimize JPEG / PNG images with imagemin, but I have a problem when using extensions, they "deoptimize", meaning the result image is bigger than the original. How can I prevent this?
This is my Gruntfile.js
...
grunt.initConfig({
imagemin: {
jpeg: {
options: {
//by default it uses imageminJpegtran
progressive: true,//default false, progressive JPEG is better compression https://superuser.com/questions/463477/progressive-jpeg-quality-compare-to-normal-jpeg
arithmetic: false,//true breaks image
//don't know how to use it loseless without making the images even bigger
// use: [
// imageminMozjpeg({
// quality: 95, //Compression quality, in range 0 (worst) to 100 (perfect).
// dcScanOpt: 2,//2 Optimize between one scan for all components and one scan for 1st component plus one scan for remaining components
// arithmetic: false// false, or it breaks the image
// }),
// ],
},
files: [{
expand: true,
cwd: '/www',
src: ['**/*.{jpg,jpeg,JPG,JPEG}'],
dest: '/www',
filter: 'isFile'
}]
}
}
});
...
You can use the
optimizationLeveloption. This value ranges from 0 to 7, with 3 as the default.For instances:
In this example the images optimized are those with the extension png, jpg, or gif, and located in the “src/images” folder and all its subfolders. The result of the optimization will be stored in the “dist” folder.
Adapted from here.