Skip to content

Instantly share code, notes, and snippets.

@mirzap
Forked from Kienz/node-image-resize.js
Created July 3, 2014 23:08
Show Gist options
  • Save mirzap/599d41456ef0b82722d9 to your computer and use it in GitHub Desktop.
Save mirzap/599d41456ef0b82722d9 to your computer and use it in GitHub Desktop.
(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