利用gulp-imagemin压缩jpg格式图片变化不大

使用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图一样压缩前后大小变化比较明显?

回复
阅读 5.9k
3 个回答
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"));
});

楼主解决了么,同样遇到这个问题,尝试用webp,效果很好,但是目前只有chrome系的才支持。

推荐问题
宣传栏