mahnunchik / gulp-responsive

gulp-responsive generates images at different sizes
https://npmjs.com/gulp-responsive
MIT License
502 stars 62 forks source link

Bug + workaround: extName option ignored for JPGs unless format: "jpg" (not format: "jpeg") #123

Closed jm3 closed 4 years ago

jm3 commented 5 years ago

As mentioned in #118 and bug bounty 72142256, the extname option to rename as described in the README does not work (it works, it just gets overriden by the implicit format), so that all JPGs are force-renamed to 'jpeg', regardless of

  1. input name,
  2. the specfied extname, or
  3. even a literal filename containing e.g. ".jpg"

… all get smashed to *.jpeg.

REPRO:

var gulp = require('gulp');
var $ = require('gulp-load-plugins')();

gulp.task('default', function () {
  return gulp.src('img-src/*.jpg')
    .pipe($.responsive({
      '*.jpg': {
        width: 200,
        rename: { 
          suffix: '-200w',
          extname: '.jpg'
        },
    }))
    .pipe(gulp.dest('public/img'));
});
npx gulp
[21:29:56] gulp-responsive: test.jpg -> test-200w.jpeg

note that test.JPG → test.JPEG, not test.JPG

WORKAROUND:

omit extname: '...' and instead pass format: 'jpg'

gulp.task('default', function () {
  return gulp.src('img-src/*.{jpg,png}')
    .pipe($.responsive({
      '*.jpg': {
        width: 200,
        rename: { 
          suffix: '-200w',
        },
        format: 'jpg'
      },
    }, {}))
    .pipe(gulp.dest('public/img'));
});
npx gulp
[21:41:45] gulp-responsive: test.jpg -> test-200w.jpg

Tada! 🎉

StarpTech commented 4 years ago

Fixed in https://github.com/mahnunchik/gulp-responsive/pull/129

krisdante commented 4 years ago

https://github.com/mahnunchik/gulp-responsive/issues/136 seems there is a regression as this problem is back