gulp-image不会压缩JPG

问题描述 投票:0回答:1

gulp-image正在压缩png文件而没有任何缺陷,但是当涉及到jpg格式时,它会保留原样。如果它有任何帮助,这里是我的配置:

var gulp = require('gulp');
var image = require("gulp-image");
var imagemin = require('gulp-imagemin');
var jpegRecompress = require("imagemin-jpeg-recompress");
var mozjpeg = require("imagemin-mozjpeg");
var jpegoptim = require('jpegoptim-bin');


// Optimization tasks
// -------------------

gulp.task("images:minify", function () {
    return gulp.src("images_src/**/*")
        .pipe(imagemin([imageminMozJpeg()], {
            verbose: true
        }))
        .pipe(gulp.dest("images_src/compressed"));
});

gulp.task("images:compress", function () {
    gulp.src("images_src/**/*.*")
    .pipe(image({
        jpegRecompress: true,
        jpegoptim: false,
        mozjpeg: true,
        concurrent: 10
    }))
    .pipe(gulp.dest("tmp"));
})

And here's what the terminal outputs when I run `gulp-image`:
[14:57:29] Using gulpfile ~/code/udacity-responsive-images/p1-my-solution/gulpfile.js
[14:57:29] Starting 'images:compress'...
[14:57:29] Finished 'images:compress' after 23 ms
[14:57:32] ✔ fixed/smiley_face.png -> before=3.8 KB after=478 B reduced=3.34 KB(87.7%)
[14:57:33] - horses.jpg -> Cannot improve upon 149.26 KB
[14:57:34] - still_life.jpg -> Cannot improve upon 81.13 KB
[14:57:35] - grasshopper.jpg -> Cannot improve upon 234.97 KB
[14:57:38] - rosella.jpg -> Cannot improve upon 676.67 KB
[14:57:39] - postcard.jpg -> Cannot improve upon 486.93 KB
[14:57:39] - cockatoos.jpg -> Cannot improve upon 485.34 KB
[14:57:39] - volt.jpg -> Cannot improve upon 522.92 KB
[14:57:39] - sfo.jpg -> Cannot improve upon 492.9 KB
[14:57:42] ✔ fixed/flourish.png -> before=43.43 KB after=15.42 KB reduced=28 KB(64.5%)

请你帮助我好吗?

gulp compression jpeg
1个回答
0
投票

我认为没有任何错误。各种jpeg压缩算法具有各种设置,您可以在其中调整压缩量。 jpeg-recompress的默认设置为:

['--strip', '--quality', 'medium', '--min', 40, '--max', 80]

参数描述在哪里:

--quality               Set a quality preset: low, medium, high, veryhigh
--min                   Minimum JPEG quality
--max                   Maximum JPEG quality
--strip                 Strip metadata

如果指定不同的质量,最小值和最大值,您将得到不同的结果。如果gulp-image没有检测到给定设置的任何压缩(即输入大小等于输出大小),它将为您提供无法改进的消息。默认设置为:

C:\a>gulp images:compress
[16:52:38] Using gulpfile ~\a\gulpfile.js
[16:52:38] Starting 'images:compress'...
[16:52:38] Finished 'images:compress' after 6.49 ms
[16:52:39] - cockatoos.jpg -> Cannot improve upon 485.34 KB

虽然这些设置:

gulp.task("images:compress", function () {
  gulp.src("images/**/*.*")
    .pipe(image({
      jpegRecompress: ['--strip', '--quality', 'medium', '--min', 1, '--max', 2],
      jpegoptim: false,
      mozjpeg: true,
      concurrent: 10,
    }))
    .pipe(gulp.dest("tmp"));
});

给出以下结果:

C:\a>gulp images:compress
[16:52:46] Using gulpfile ~\a\gulpfile.js
[16:52:46] Starting 'images:compress'...
[16:52:46] Finished 'images:compress' after 6.4 ms
[16:52:48] ✔ cockatoos.jpg -> before=485.34 KB after=84.93 KB reduced=400.42 KB(82.5%)

现在凤头鹦鹉看起来很糟糕,但我猜你可以四处寻找体面的设置。看起来gulp-image正如我所看到的那样正常工作。

Cockatoos

© www.soinside.com 2019 - 2024. All rights reserved.