Open In App

Node.js GM orderedDither() Function

The orderedDither() function is an inbuilt function in the GraphicsMagick library which is used to order dither the image. The ordered dither method is used to reduce channel or channel type argument into binary. The values of channel type are All, Intensity, Red, Green, Blue, Cyan, Magenta, Yellow, Black, and Opacity. The function returns the true value of success. 

Syntax:



orderedDither( ChannelType, NxN )

Parameters: This function accepts two parameters as mentioned above and described below:

Return Value: This function returns the GraphicsMagick object.



 Example 1: 




// Include gm library
const gm = require('gm');
 
// Import the image
gm('1.png')
 
// Invoke ordered Dither on Green
// Channel with 50 x 60
.orderedDither('Green', '50x60')
 
// Process and Write the image
.write("orderedDither1.png", function (err) {
    if (!err) console.log('done');
});

Output:

  

Example 2: 




// Include gm library
const gm = require('gm');
 
//Import the image
gm(600, 300, 'white')
 
// set the color for the stroke
.stroke("green", 3)
 
// Set the font
.font("Helvetica.ttf", 60)
 
//Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
 
// Invoke ordered Dither with 'All'
// Channel with 110 x 110
.orderedDither('All', '110x110')
 
// Process and write the image
.write("ordereddither2.png", function (err) {
    if (!err) console.log('done');
});

Output:

  

Reference:


Article Tags :