Last active
June 21, 2017 20:33
-
-
Save jimthoburn/9799536fc0294c027e8b03063ae56061 to your computer and use it in GitHub Desktop.
Gulp Resize Images, Example
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
// https://github.com/gulpjs/gulp | |
var gulp = require('gulp'); | |
// https://www.npmjs.com/package/gulp-image-resize | |
var imageResize = require('gulp-image-resize'); | |
var parallel = require("concurrent-transform"); | |
var os = require("os"); | |
const SIZES = [384, 512, 768, 1024, 1536, 2048]; | |
function generateImages(size) { | |
gulp.src("images/original/*.{jpg,png}") | |
.pipe(parallel( | |
imageResize({ width : size }), | |
os.cpus().length | |
)) | |
.pipe(gulp.dest("images/" + size + "-wide")); | |
} | |
gulp.task("default", function() { | |
SIZES.forEach(generateImages); | |
}); |
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
{ | |
"name": "resize-images", | |
"version": "1.0.0", | |
"description": "", | |
"main": "gulpfile.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "jim@jimthoburn.com", | |
"license": "MIT", | |
"devDependencies": { | |
"concurrent-transform": "^1.0.0", | |
"gulp": "^3.9.1", | |
"gulp-image-resize": "^0.12.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment