The posterize() function is an inbuilt function in Nodejs | Jimp that applies a posterize effect with n level.
Syntax:
posterize(n, cb)
Parameter:
- n: This parameter stores the amount to adjust the contrast and the minimum threshold is two
- cb: This is an optional parameter that is invoked when compilation is complete.
Input Images:
Step 1: Setting up the environment
npm init -y
Step 2: Install jimp
npm install jimp --save
Example 1:In this example, we will apply the posterize effect.
javascript
const Jimp = require( 'jimp' );
async function main() {
const image = await Jimp.read(
image.posterize(4)
.write( 'posterize1.png' );
}
main();
console.log( "Image Processing Completed" );
|
Output:
Example 2: With cb (optional parameters)
javascript
const Jimp = require( 'jimp' );
async function main() {
const image = await Jimp.read(
image.posterize(5, function (err) {
if (err) throw err;
})
.write( 'posterize2.png' );
}
main();
console.log( "Image Processing Completed" );
|
Output:
Reference: https://www.npmjs.com/package/jimp
Last Updated :
27 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...