Rumah > Soal Jawab > teks badan
使用gulp-imagemin压缩图片,对于png图,压缩前后变化还是挺明显的,但是压缩jpg图片变化很小,gulpfile的设置如下:
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
const imageminPngquant = require('imagemin-pngquant');
const imageminJpegtran = require('imagemin-jpegtran');
gulp.task('default', () =>
gulp.src('src/images/*')
.pipe(imagemin({
use:[imageminPngquant(),imageminJpegtran()]
}))
.pipe(gulp.dest('dist/images'))
);
如何让压缩的jpg也像png图一样压缩前后大小变化比较明显?
PHPz2017-04-17 14:49:53
gulp.task('imgmin', function () {
var jpgmin = imageminJpegRecompress({
accurate: true,//高精度模式
quality: "high",//图像质量:low, medium, high and veryhigh;
method: "smallfry",//网格优化:mpe, ssim, ms-ssim and smallfry;
min: 70,//最低质量
loops: 0,//循环尝试次数, 默认为6;
progressive: false,//基线优化
subsample: "default"//子采样:default, disable;
}),
pngmin = imageminOptipng({
optimizationLevel: 4
});
gulp.src("src/img/*.*")
.pipe(imagemin({
use: [jpgmin, pngmin]
}))
.pipe(gulp.dest("dist/img"));
});