Gulp plug-in GULP-IMAGEMIN,IMAGEMIN-PNGQUANT-GFW and Gulp-cache

Source: Internet
Author: User

Introduction to GULP-IMAGEMIN,IMAGEMIN-PNGQUANT-GFW and Gulp-cache :

            gulp-imagemin plugin is used to compress picture files (including png,jpeg,gif and SVG images).

             IMAGEMIN-PNGQUANT-GFW plugin is used to compress image files in PNG format in depth.

     The         gulp-cache plugin is used to read cache files. Compressing pictures can take a long time, and using "Gulp-cache"   plugins can reduce repetitive compression.        

I. "GULP-IMAGEMIN,IMAGEMIN-PNGQUANT-GFW and Gulp-cache "  plug-in use

1, Install "GULP-IMAGEMIN,IMAGEMIN-PNGQUANT-GFW and Gulp-cache plug-in commands (executed at Terminal entry to project root)

NPM Install--save-dev gulp-load-plugins gulp-imagemin gulp-cache IMAGEMIN-PNGQUANT-GFW

2, in the project root directory to provide "Gulp-imagemin" plug-in task configuration required src directory and source files (source files placed in the SRC directory)

mkdir SRC

3. Configure the use of "GULP-IMAGEMIN,IMAGEMIN-PNGQUANT-GFW and Gulp-cache" in the Gulpfile.js file

Specific examples:
Use only the Gulp-imagemin plugin
var gulp = require (' Gulp '),
Plugins = require (' Gulp-load-plugins ') (); Loading plugins

Gulp.task (' Imagemin ', function () {//Custom "Imagemin" task
Return Gulp.src (' src/images/*.{ Png,jpeg,gif} ')//blur match all picture files under Src/images directory
. Pipe (Plugins.imagemin ({
Optimizationlevel:5,//Type: Number default: 3 Value range: 0-7 (Optimization level)
Progressive:true,//Type: Boolean default: False lossless compression jpg picture
Interlaced:true,//Type: Boolean default: False to render with interlaced GIF
Multipass:true//Type: Boolean default: False optimizes SVG multiple times until fully optimized
}))
. Pipe (Gulp.dest (' dist/img ')); File storage path after compression
});

Specific examples:
Using the "GULP-IMAGEMIN,IMAGEMIN-PNGQUANT-GFW and Gulp-cache" plugin
Because some pictures are larger, it is possible to compress them in depth and compress only the modified pictures, which are read from the cache without modification.
var gulp = require (' Gulp '),
Pngquant = require (' IMAGEMIN-PNGQUANT-GFW '),
Plugins = require (' Gulp-load-plugins ') (); Loading plugins

Gulp.task (' Imagemin ', function () {//Custom "Imagemin" task
Return Gulp.src (' src/images/*.{ Png,jpeg,gif} ')//blur match all picture files under Src/images directory
. Pipe (Plugins.cache (Plugins.imagemin ({
Progressive:true,//Type: Boolean default: False lossless compression jpg picture
Svgoplugins: [{removeviewbox:false}],//Do not remove the Viewbox attribute of the SVG picture
Use: [Pngquant ({//Deep compress PNG format picture
Quality: ' 65-80 ',//Picture quality
Speed:4//Compression rate
})]
})))
. Pipe (Gulp.dest (' dist/img ')); File storage path after compression
});

4, finally run "Gulp imagemin" command in terminal

PS: If there is no error message, prove that there is no problem. Now go to the project root to see if the "dist/img" directory and the target file are generated. Not to be continued.




This article from "Luo Chen's Blog" blog, reproduced please contact the author!

Gulp plug-in GULP-IMAGEMIN,IMAGEMIN-PNGQUANT-GFW and Gulp-cache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.