Created
June 12, 2015 11:13
-
-
Save chmanie/936012ad005c47dc5a1f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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