Nodejs | GM orderedDither() Function

The orderedDither() function is an inbuilt function in the GraphicsMagick library which is used to ordered dither the image. The ordered dither method is used to reduce channel or channeltype argument into binary. The values of channeltype are All, Intensity, Red, Green, Blue, Cyan, Magenta, Yellow, Black, and Opacity. The function returns the true value on 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:



filter_none

edit
close

play_arrow

link
brightness_4
code

// Include gm library
var 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');
});

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Include gm library
var 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');
});

chevron_right


Output:

Reference:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.