Skip to content
Related Articles

Related Articles

Improve Article

Node Jimp | normalize

  • Last Updated : 22 Feb, 2021

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 environment
var Jimp = require('jimp');
 
// User-Defined Function to read the images
async 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 environment
var Jimp = require('jimp');
 
// User-Defined Function to read the images
async 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
 




My Personal Notes arrow_drop_up
Recommended Articles
Page :