效果
安装:
"dependencies": {
"imagemin": "^7.0.1",
"imagemin-pngquant": "^9.0.1"
}
zip.js
const imagemin = require('imagemin');
const imageminPngquant = require('imagemin-pngquant');
(async () => {
const files = await imagemin(['screenImg/*.{jpg,png}'], {
destination: 'zipImgs', // 输出文件夹
plugins: [
imageminPngquant({
quality: [0.6, 0.8] // 输出图片质量
})
]
});
console.log(files);
//=> [{data: <Buffer 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]
})();
images 只可以压缩.jpg的图片,对于.png的不处理,jpeg参考下面的文章
原文链接:https://zhuanlan.zhihu.com/p/93882055
新增功能:将生成的文件夹进行打包
效果
安装:
npm i zip-local -S
使用:
var zipper = require("zip-local");
zipper.sync.zip(outPutFolder).compress().save("images.zip")
继续扩展之后实现是这样
1,实现将之前的图片文件体积压缩大概50%
2.将文件夹打包为zip