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 that is invoked when compilation is complete.
Input Images:
Setup Environment :
npm init -y
Install Dependencies :
npm install jimp
Example 1: In this example, we will see the use of normalize().
javascript
// npm install --save jimp // import jimp library to the environment const 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 const 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