- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to blur an image using Node Jimp blur() function?
NodeJS – Blur() is an inbuilt function that is used to blur images. The effect produced by JIMP blur() will be similar to that of the Gaussian blur. It blurs based on the pixels input.
Syntax
blur(r, cb)
Definition of blur() paramters
r – It takes the input for blur and blurs based upon the pixels. If r is 2, it will blur 2 pixels at a time.
cb – This is an optional parameter that can be invoked after the compilation is complete.
Input Image
Using Node JIMP – BLUR()
Before proceeding to use blur() functions, please check that the following statements arealready executed for setting up the environment.
npm init -y // Initialising the Node environment
npm install jimp --save // Installing the jimp dependency
Create a blur.js file and copy-paste the following code snippet in it.
Use node blur.js to run the code.
Note – Note that the method name should match with the JS file name. Only then it will be able to call the desired method.
Example
const Jimp = require('jimp') ; async function blur() { // Function name is same as of file name // Reading Image const image = await Jimp.read ('/home/jimp/tutorials_point_img.jpg'); image.blur(3) .write('/home/jimp/blur.jpg'); } blur(); // Calling the function here using async console.log("Image is processed successfully");
Output
Using Node JIMP – BLUR() with 'cb' parameters
Example
const Jimp = require('jimp') ; async function blur() { // Reading Image const image = await Jimp.read ('/home/jimp/tutorials_point_img.jpg'); image.blur(7, function(err){ if (err) throw err; }) .write('/home/jimp/blur.jpg'); } blur(); console.log("Image is processed successfully");