Skip to content

Instantly share code, notes, and snippets.

@chmanie
Created June 12, 2015 11:13
Show Gist options
  • Save chmanie/936012ad005c47dc5a1f to your computer and use it in GitHub Desktop.
Save chmanie/936012ad005c47dc5a1f to your computer and use it in GitHub Desktop.
var imageAutoresizeConfig = {
types: '**/*.{jpg,jpeg,png}',
versions : [
{
width: 640,
suffix: '_mobile'
}, {
width: 800,
suffix: '_medium'
}
]
};
// TODO: implement imagemin etc., autoresizing etc.
gulp.task('images', [], function(done) {
var stream = gulp.src(paths.images, {
base: paths.app
})
.pipe(g.if(isProduction, g.imagemin()))
.pipe(gulp.dest(paths.dist));
// autoresizing if configured
var versions = imageAutoresizeConfig.versions || [];
if (imageAutoresizeConfig && imageAutoresizeConfig.types) {
stream = stream.pipe(g.filter(imageAutoresizeConfig.types));
versions.forEach(function(version) {
stream = stream.pipe(parallel(
g.imageResize({ width: version.width }),
os.cpus().length
))
.pipe(g.rename(function(path) {
if (path.extname !== '') {
path.basename += version.suffix;
}
}))
.pipe(gulp.dest(paths.dist));
});
}
return stream;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment