Node Jimp | normalize
Introduction : The normalize() function is an inbuilt function in Nodejs | Jimp which normalizes the colors of an image by computing a histogram.
Syntax:
normalize(cb)
Parameter:
- cb – This is an optional parameter which is invoked when compilation is complete.
Input Images:


Setup Environment :
npm init -y
Install Dependencies :
npm install jimp
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// normalize Function image.normalize() .write('normalize1.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// Normalize Function having callback function image.normalize(function(err){ if (err) throw err; }) .write('normalize2.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.


