Neither gulp-tinypng nor gulp-imagemin optimise png

159 Views Asked by At

I want to add a png optimizer in my gulp workflow. I've tried to both gulp-tinypng and gulp-imagemin.

I work with gulp 4.0.0
Here are my functions :

function tinypng() {
  return (
    gulp
      .src(pkg.paths.src.img + '**/*.png')
      .pipe($.cache($.tinypng('MyApiKey')))      
      .pipe(gulp.dest(pkg.paths.prod.img))              // Envoie le fichier dans le dossier de production
      .pipe($.browserSync.stream())                     // Relance le browser
      .pipe($.notify({ message: 'Png task complete' })) 
  );
}

function images() {
  return (
    gulp
      .src(pkg.paths.src.img + '**/*.*')
      .pipe($.cache($.imagemin([ 
        $.imagemin.gifsicle({interlaced: true}),
        $.imagemin.jpegtran({progressive: true}),
        $.imagemin.optipng({optimizationLevel: 7}) 
        ])))                                                // cache et optimise les images
      .pipe(gulp.dest(pkg.paths.prod.img))                  // Envoie le fichier dans le dossier de production
      .pipe($.browserSync.stream())                         // Relance le browser
      .pipe($.notify({ message: 'Images task complete' })) 
  );
}

gulp.task('tinypng', tinypng);
gulp.task('images', images);

I run my test with a png weighting 1002 Ko.

If I use the website tinypng, the weight goes down to 279 Ko

Both functions run smoothly, no error, files are copied where they should be, but the weight of the files isn't reduce. It's like it's copying the original file.

I'd be glad to get some help here, because I don't understand what's happening.

0

There are 0 best solutions below