What is @jimp/plugin-rotate?
@jimp/plugin-rotate is a plugin for the Jimp image processing library that provides functionality to rotate images. It allows users to rotate images by a specified number of degrees, either clockwise or counterclockwise.
Rotate Image
This feature allows you to rotate an image by a specified number of degrees. In this example, the image is rotated by 90 degrees and then saved to a new file.
const Jimp = require('jimp');
Jimp.read('path/to/image.jpg')
.then(image => {
return image.rotate(90) // rotate image by 90 degrees
.write('path/to/rotated-image.jpg'); // save
})
.catch(err => {
console.error(err);
});
Rotate Image with Background Color
This feature allows you to rotate an image by a specified number of degrees and fill the background with a specified color. In this example, the image is rotated by 45 degrees with a white background.
const Jimp = require('jimp');
Jimp.read('path/to/image.jpg')
.then(image => {
return image.rotate(45, false, 0xFFFFFFFF) // rotate image by 45 degrees with white background
.write('path/to/rotated-image.jpg'); // save
})
.catch(err => {
console.error(err);
});