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
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"
jimp.read("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 !!
We have learned how we can resize an image in node.js using jimp
.