Node Jimp | pixelate
Last Updated :
27 Mar, 2023
The pixelate() function is an inbuilt function in Nodejs | Jimp that applies the pixelation effect over an image or region.
Syntax:
pixelate(size, x, y, w, h, cb)
Parameter:
- size: This parameter takes the size of the pixels.
- x: This parameter takes the x position of the region to pixelate.
- y: This parameter takes the y position of the region to pixelate.
- w: This is an optional parameter that takes the width of the region to pixelate.
- h: This is an optional parameter that takes the height of the region to pixelate.
- 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 pixelate().
javascript
const Jimp = require( 'jimp' );
async function main() {
const image = await Jimp.read( '../gfg.png' );
image.pixelate(5)
.write( 'pixelate1.png' );
}
main();
console.log( "Image Processing Completed" );
|
Output:
Example 2: With size, x, y, w, h, and cb (optional parameters)
javascript
const Jimp = require( 'jimp' );
async function main() {
const image = await Jimp.read( '../gfg1.png' );
image.pixelate(5, 40, 50, 190, 200, function (err) {
if (err) throw err;
})
.write( 'pixelate2.png' );
}
main();
console.log( "Image Processing Completed" );
|
Output:
Reference: https://www.npmjs.com/package/jimp
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...