Grunt-contrib-imagemin: Image compression
Install plugin: npm install grunt-contrib-imagemin--save-dev
Parameters
Optimizationlevel (PNG)
Type: Number
Default value: 3
Select an optimization level of 0 to 7.
Progressive (JPG)
Type: Boolean
Default: True
Lossless conversion.
Interlaced (GIF)
Type: Boolean
Default: True
Interlaced GIF is progressively rendered.
Svgoplugins (SVG)
Type: Array
Default: []
Customize which svgo plugin to use.
Use
Type: Array
Default: null
Additional plugins are used with imagemin.
1. Dynamically compress pictures within a folder
imagemin: {/*Compress picture size*/Dist: {options: {optimizationlevel :3 //define PNG picture optimization levels}, files: [{expand:true, CWD:'img/', src: ['**/*. {Png,jpg,jpeg}'],//optimize all png/jpg/jpeg images in the IMG directoryDest'img1/' //optimized picture save location, overwrite old picture, without prompting }] }}
2. Compress Pictures statically
imagemin: {/*Compress picture size*/Dist: {options: {optimizationlevel :3 //define PNG picture optimization levels}, files: {'img1/1.jpg':'img/1.jpg', 'img1/2.jpg':'img/2.jpg' } }}
Grunt-contrib-imagemin image Compression