Rumah  >  Soal Jawab  >  teks badan

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

迷茫迷茫2766 hari yang lalu733

membalas semua(2)saya akan balas

  • PHPz

    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"));
    });

    balas
    0
  • 大家讲道理

    大家讲道理2017-04-17 14:49:53

    请问楼主解决了没, 而且感觉压缩的速度很慢, 有什么办法可以加快压缩速度吗?

    balas
    0
  • Batalbalas