Open In App

Node.js GM whiteThreshold() Function

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:

Return Value: This function returns the GraphicsMagick object. 



Original Image:

  

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




// 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. 




// 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:


Article Tags :