Node Jimp | rotate
Introduction
The rotate() function is an inbuilt function in Nodejs | Jimp which rotates the image clockwise and the dimensions of the image remain same.
Syntax:
rotate(r, mode, cb)
Parameter:
- r – This parameter stores the rotation angle for the image.
- mode – This is optional parameter which stores the scaling method.
- cb – This is optional parameter which is invoked when compilation is complete.
Input Images:


Step 1 : Setting up environment
npm init -y
Step 2 : Install jimp
npm install jimp --save
Example 1:
javascript
// npm install --save jimp// import jimp library to the environmentvar Jimp = require('jimp');// User-Defined Function to read the imagesasync function main() { const image = await Jimp.read// rotate Function having a rotation as 55 image.rotate(55) .write('rotate1.png');}main(); console.log("Image Processing Completed"); |
Output:

Example 2: With mode and cb (optional parameters)
javascript
// npm install --save jimp// import jimp library to the environmentvar Jimp = require('jimp');// User-Defined Function to read the imagesasync function main() { const image = await Jimp.read// rotate Function having rotation angle as 99, mode and callback function image.rotate(99, Jimp.RESIZE_BEZIER, function(err){ if (err) throw err; }) .write('rotate2.png');}main(); console.log("Image Processing Completed"); |
Output:

Reference: https://www.npmjs.com/package/jimp
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

