Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to spin the hue of an image using Jimp in NodeJS?
NodeJS – spin modifier is an inbuilt function that is used to spin the hue of an image to a given amount from -360° to 360°. We can spin the color from 0 to 360, but it will not perform any function, as it sets the hue back to what it was before.
Syntax
image.color([
{apply: 'spin', params: [value] }
]);
color() paramters
value – It will store the amount of hue to be applied while spinning. Its possible values are from -360 to 360.
Input Image

Using Node JIMP – COLOR – SPIN
Before proceeding to use color() – spin functions, please check that the following statements are already executed for setting up the environment.
npm init -y // Initialising the Node environment
npm install jimp --save // Installing the jimp dependency
Create a colorSpin.js file and copy-paste the following code snippet in it.
Use node colorSpin.js to run the code.
Note − Note that the method name should match with the JS file name. Only then it will be able to call the desired method.
Example
const Jimp = require('jimp') ;
async function colorSpin() {
// Reading Image
const image = await Jimp.read
('/home/jimp/tutorials_point_img.jpg');
image.color([{apply: 'spin', params: [50]}])
.write('/home/jimp/colorSpin.jpg');
}
colorSpin(); // Calling the function here using async
console.log("Image is processed successfully");
Output

Using Node JIMP – Color - SPIN with 'cb' parameters
Example
const Jimp = require('jimp') ;
async function colorSpin() {
// Reading Image
const image = await Jimp.read
('/home/jimp/tutorials_point_img.jpg');
image.color([{apply:'spin', params: [100]}], function(err){
if (err) throw err;
})
.write('/home/jimp/colorSpin.jpg');
}
colorSpin();
console.log("Image is processed successfully");
Output

