EasyImage – Nodejs Image Processing Module
Today’s featured web development tool is called EasyImage from hacksparrow, a module that will make image processing and manipulation in Node.js a little more less complicated, not just for beginners but advanced users as well. Server side technologies like ImageMagick is one of the most popular choices for image processing in Node.js, but its syntax can be so complicated and the method of calling it only makes things even worse for the developer. That’s where EasyImage comes in!
EasyImage is built on top of ImageMagick, so in order for you to use it, you first must need to have the latter installed.
Installing ImageMagick on Ubuntu
$ apt-get install imagemagick
Installing ImageMagick on Mac OS X
$ brew install imagemagick
Installing ImageMagick on CentOS
$ yum install imagemagick
Installing EasyImage
$ npm install easyimage
To use EasyImage, simply do
var easyimg = require('easyimage');
And then you simply call its methods to perform various image manipulation tasks like resizing, cropping, etc. Examples below:
To convert an image’s format to another:
easyimg.convert(<options>, <callback_function>)
In application, it’ll look something like this:
easyimg.convert({src:'beach.jpg', dst:'beach.png', quality:10}, function(err, stdout, stderr) {
if (err) throw err;
console.log('Converted JPG to PNG, quality set at 10/100');
});
You can specify the quality level of the image from 0 to 100 (with 100 being the best and 0 the worst)
To resize an image:
easyimg.resize(<options>, <callback_function>)
Hence,
easyimg.resize({src:'beach.jpg', dst:'beach-small.jpg', width:640, height:480}, function(err, stdout, stderr) {
if (err) throw err;
console.log('Resized to 640x480');
});
You can find more examples HERE. Last but not least, you can execute ImageMagic convert commands yourself from EasyImage.