Open In App

Node.js GM whiteThreshold() Function

Last Updated : 29 Mar, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The whiteThreshold() function is an inbuilt function in the GraphicsMagick library which is used to force all pixels above the threshold into white while leaving all pixels below the threshold unchanged. The function returns the true value of success. 

Syntax:

whiteThreshold( intensity )
whiteThreshold( red, green, blue, opacity )

Parameters: This function accepts parameters in two fashions which are mentioned above and described below:

  • intensity/red: If only a single parameter is mentioned, then this parameter is taken as intensity by the function otherwise it is taken as red intensity.
  • green: This parameter is used to specify the green intensity.
  • Blue: This parameter is used to specify the blue intensity.
  • opacity: This parameter is used to specify the opacity intensity.

Return Value: This function returns the GraphicsMagick object. 

Original Image:

  

Example 1: Passing only a single parameter which is taken as an intensity value. 

javascript




// Include gm library
const gm = require('gm');
 
// Import the image
 
// Invoke whiteThreshold function with 0.2 value
.whiteThreshold(.2)
 
// Process and Write the image
.write("whiteThreshold1.png", function (err) {
  if (!err) console.log('done');
});


Output:

  

Example 2: Mentioning red, blue, and green intensity. 

javascript




// Include gm library
const gm = require('gm');
 
// Import the image
 
    // Invoke whiteThreshold function
    // with .0001, 0.00001, 12, 0.11
    .whiteThreshold(.0001, 0.00001, 12, 0.11)
 
    // Process and Write the image
    .write(& quot; whiteThreshold2.png & quot;, function (err) {
        if (!err) console.log('done');
    });


Output:

  

Reference:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads