Image batch resize in node.js

Image batch resize in node.js.

var async = require(‘async’), fs = require(‘fs’), im = require(‘imagemagick’), maxworkers = require(‘os’).cpus().length, path = require(‘path’); module.exports = resize; function resize(params) { var queue = async.queue(resizeimg, maxworkers); fs.readdir(params.src, function(err, files) { files.forEach(function(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 (params.width !== undefined) imoptions.width = params.width; if (params.height !== undefined) imoptions.height = params.height im.resize(imoptions, cb); }

resize({ src: ‘/source/folder’, dest: ‘/destination/folder’, width: 300 });



This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s