- 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 adjust the contrast of an image using contrast() function in Node Jimp?
NodeJS – Contrast() is an inbuilt function that is used to adjust the contrast of images. It will increase or decrease the contrast based upon the input value that ranges from -1 to +1.
Syntax
contrast(n, cb)
Definition of contrast() paramters
n – It will take n as an input for adjusting the contrast of the image, Possible values of n is between -1 and +1.
cb – This is an optional parameter that can be invoked after the compilation is complete.
Input Image
Using Node JIMP – CONTRAST()
Before proceeding to use contrast() functions, please check that the following statements are already executed for setting up the environment.
npm init -y // Initialising the Node environment
npm install jimp --save // Installing the jimp dependency
Create a contrast.js file and copy-paste the following code snippet in it.
Use node contrast.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 contrast() { // Function name is same as of file name // Reading Image const image = await Jimp.read ('/home/jimp/tutorials_point_img.jpg'); image.contrast(.4) .write('/home/jimp/contrast.jpg'); } contrast(); // Calling the function here using async console.log("Image is processed successfully");
Output
Using Node JIMP – Contrast() with 'cb' parameters
Example
const Jimp = require('jimp') ; async function contrast() { // Reading Image const image = await Jimp.read ('/home/jimp/tutorials_point_img.jpg'); image.contrast(-0.5, function(err){ if (err) throw err; }) .write('/home/jimp/contrast.jpg'); } contrast(); console.log("Image is processed successfully");
Output
- Related Articles
- How to adjust the contrast of an image in PyTorch?
- How to blur an image using Node Jimp blur() function?
- How to crop an image using crop() function in Node Jimp?
- How to alter the contrast of an image using Java OpenCV library?
- Adjusting the Image Contrast using CSS3
- How to change the contrast and brightness of an image using OpenCV in Python?
- How to flip an image in Node Jimp?
- How to resize an image in Node Jimp?
- How to rotate an image in Node Jimp?
- How to set the brightness and contrast of an image with JavaScript?
- Altering the brightness and contrast of an image using JavaFX and OpenCV
- How to invert the colors of an image in Node Jimp?
- How to change the opacity of an image in Node Jimp?
- How to change an image to greyscale in Node Jimp?
- How to apply Posterize to an image in Node Jimp?
