derhuerst / gulp-scale-images

Gulp plugin to resize each image into multiple smaller variants.
https://github.com/derhuerst/gulp-scale-images#gulp-scale-images
ISC License
13 stars 5 forks source link

Gulp v5 needs encoding: false #35

Open MatthiasKuehneEllerhold opened 3 months ago

MatthiasKuehneEllerhold commented 3 months ago

Updating to gulp v5 all my worflows with gulp-scale-images were broken: "Error: Input buffer contains unsupported image format"

There was only one result in google for this error, but this pointed towards a problem with svgs and sharp.

Gulp v5 changed the default encoding of all of their streams to UTF-8. gulp-scale-images does not seem aware of this and expects a binary stream?

What you have to do is set encoding to false on your streams.

return gulp
  // Load file
  .src(data.source, {encoding: false})

  // We want to have multiple sizes per source image
  .pipe(flatMap.default(variantsPerFile))

  // Scale the images
  .pipe(scaleImages(computeFileName))

  // Write result file
  .pipe(gulp.dest(application.destinationPath + '/' + key));

With this change my workflow are once again working correctly.

Can you either add this to the README or somehow fix this in code?

derhuerst commented 1 month ago

PR welcome!