Resize Images

Resize image using jimp module of node.js

30 Days of Node | Node.js Tutorial series


In this article we will learn how we can resize an image in node.js using jimp package.


We can install the jimp package using the following command:

>npm install jimp												

Image Resizing

Suppose we want to resize yellow.png which is in the same directory as our code. We can perform it in the following way :

//Name of the File : image-resize-jimp.js
var jimp = require("jimp");
// open a file called "yellow.png""yellow.png", function (err, img) {
    if (err) throw err;
    img.resize(500, 500)            // resize
         .quality(70)                 // set JPEG quality
         .greyscale()                 // set greyscale
         .write("yellow-med.jpg"); // save
          console.log('Resized !!')


We can run the code using the following command and we will get the output shown below:

>node image-resize-jimp.js	
Resized !!										

The resized output image will be stored in the same directory as the input image.


We have learned how we can resize an image in node.js using jimp.