-
-
Save mirzap/599d41456ef0b82722d9 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
(function() { | |
'use strict'; | |
var async = require('async'), | |
fs = require('fs'), | |
im = require('imagemagick'), | |
maxworkers = require('os').cpus().length, | |
path = require('path'); | |
exports.resize = resize; | |
function resize(params) { | |
var queue = async.queue(resizeimg, maxworkers); | |
fs.readdir(params.src, function(err, files) { | |
files.forEach(function(file) { | |
console.log('resize: ', file); | |
queue.push({ | |
src: path.join(params.src, '/', file), | |
dest: path.join(params.dest, '/', file), | |
width: params.width, | |
height: params.height | |
}); | |
}); | |
}); | |
} | |
function resizeimg(params, cb) { | |
var imoptions = { | |
srcPath: params.src, | |
dstPath: params.dest | |
}; | |
if (typeof params.width !== 'undefined') { | |
imoptions.width = params.width; | |
} | |
if (typeof params.height !== 'undefined') { | |
imoptions.height = params.height; | |
} | |
im.resize(imoptions, cb); | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment