Introduction
The pixelate() function is an inbuilt function in Nodejs | Jimp which applies 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 which takes the width of the region to pixelate.
- h – This is an optional parameter which takes the height of the region to pixelate.
- cb – This is an optional parameter which is invoked when compilation is complete.
Input Images:


Example 1:
//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('../gfg.png'); // pixelate function 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)
//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('../gfg1.png'); //pixelate function using callback function 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
Recommended Posts:
- Node Jimp | flip
- Node Jimp | Gaussian
- Node Jimp | Blit
- Node Jimp | Blur
- Node Jimp | scaleToFit
- Node Jimp | scale
- Node Jimp | rotate
- Node Jimp | resize
- Node Jimp | normalize
- Node Jimp | posterize
- Node Jimp | opacity
- Node Jimp | sepia
- Node Jimp | invert
- Node Jimp | fade
- Node Jimp | brightness
- Node | Jimp | contrast
- Node Jimp | Crop
- Node Jimp | Color Lighten
- Node Jimp | Color darken
- Node Jimp | Color Brighten
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

