Open In App

Node.js GM orderedDither() Function

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

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:

  • ChannelType: This parameter is used to specify the Channel Type as All, Intensity, Red, Green, Blue, Cyan, Magenta, Yellow, Black, and Opacity.
  • NxN: This parameter is used to specify the minimum and maximum level of the intensity.

Return Value: This function returns the GraphicsMagick object.

 Example 1: 

javascript




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

javascript




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



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

Similar Reads