-
-
Save JonathanMH/3742525 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fs = require('fs'); | |
var im = require('imagemagick'); | |
var async = require('async'); | |
var widths = ['270', '590', '910', '1230']; | |
var source_dir = process.cwd()+'/source/'; | |
var output_dir = process.cwd()+'/output/'; | |
fs.readdir(source_dir, function(err, files){ | |
if (err) throw err; | |
console.log(files); | |
var parallelResizes = 1; | |
async.mapSeries(files, function (file, cb) { | |
im.identify(source_dir + file, cb); | |
}, | |
function (err, identifiers) { | |
var queue = async.queue(function (options, callback) { | |
im.resize(options, callback); | |
}, parallelResizes); | |
identifiers.forEach(function (id, file) { | |
filename = files[file].split('.'); | |
for(i = 0; i < widths.length; i++){ | |
aspect = id.width / id.height; | |
width = widths[i]; | |
height = Math.round(widths[i] / aspect); | |
current = { | |
srcPath: source_dir + files[file], | |
width: width, | |
height: height, | |
dstPath: output_dir + filename[0] + '_w' + width + '_h' + height + '.' + filename[1], | |
quality: 1, | |
progressive: true | |
}; | |
queue.push(current); | |
} | |
}); | |
queue.drain = function () { | |
console.log("resizing complete"); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment