Skip to content

Instantly share code, notes, and snippets.

@gustavoquinalha
Created April 27, 2017 14:04
Show Gist options
  • Save gustavoquinalha/7759b60b3ed2dc6ee076b54bea53bf41 to your computer and use it in GitHub Desktop.
Save gustavoquinalha/7759b60b3ed2dc6ee076b54bea53bf41 to your computer and use it in GitHub Desktop.
var responsive = require('gulp-responsive');
var load = require('gulp-load-plugins')();
gulp.task('resize-img', function () {
return gulp.src('img/*.{jpg,png}')
.pipe(load.responsive({
'*.jpg': [{
width: 100,
rename: {
suffix: '-thumb',
}
}, {
width: 300,
rename: {
suffix: '-medium',
// extname: '.jpg',
},
}, {
width: 900,
rename: {
suffix: '-big',
},
// Do not enlarge the output image if the input image are already less than the required dimensions.
withoutEnlargement: true,
}],
'*.png': [{
width: 100,
rename: {
suffix: '-thumb',
}
}, {
width: 300,
rename: {
suffix: '-medium',
// extname: '.jpg',
},
}, {
width: 900,
rename: {
suffix: '-big',
},
// Do not enlarge the output image if the input image are already less than the required dimensions.
withoutEnlargement: true,
}]
}, {
// Global configuration for all images
// The output quality for JPEG, WebP and TIFF output formats
quality: 70,
// Use progressive (interlace) scan for JPEG and PNG output
progressive: true,
// Strip all metadata
withMetadata: false,
// Do not emit the error when image is enlarged.
errorOnEnlargement: false,
}))
.pipe(gulp.dest('img/dist'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment