Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp-image-resize With Multiple Images

Is it possible to have gulp-image-resize spit out multiple images, for example a @1x and @2x image. My gulp task looks like this currently:

gulp.task('images', function() {
  return gulp.src('test.jpg')
    .pipe(imageResize({ width: 1920 }))
    .pipe(imagemin({
      progressive: true
    }))
    .pipe(rename({
      suffix: '@2x'
    }))
    .pipe(gulp.dest('./_site/public/img'))
    .pipe(imageResize({ width: 960 }))
    .pipe(imagemin({
      progressive: true
    }))
    .pipe(gulp.dest('./_site/public/img'))
});

But it just places an image called [email protected] with a width of 960px into my destination directory.

Is there a way to have two images saved. One called test.jpg with a width of 960px, and one called [email protected] with a width of 1920px?

Any help is appreciated. Thanks in advance!

like image 610
realph Avatar asked May 20 '26 02:05

realph


1 Answers

You are renaming the file too early, just put the rename pipe after the first gulp.dest.

gulp.task('images', function() {
  return gulp.src('test.jpg')
    .pipe(imageResize({ width: 1920 }))
    .pipe(imagemin({
      progressive: true
    }))
    .pipe(gulp.dest('./_site/public/img')) // move this line to before the gulp.dest
    .pipe(rename({
      suffix: '@2x'
    }))
    .pipe(imageResize({ width: 960 }))
    .pipe(imagemin({
      progressive: true
    }))
    .pipe(gulp.dest('./_site/public/img'))
});
like image 195
iforwms Avatar answered May 24 '26 07:05

iforwms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!