Nodejs | GM charcoal() Function

The charcoal() function is an inbuilt function in the GraphicsMagick library which is used to add a charcoal filter to the image. The function returns the true value on success.

Syntax:

charcoal( factor )

Parameters: This function accepts single parameter which is mentioned above and described below:

  • factor: This parameter stores the value of the charcoal factor which is to be apply on the image.

Return Value: This function returns Gmagick charcoal image.

Original Image:



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 Charcoal function
// with charcoal factor as 12
.charcoal(4)
  
// Process and Write the image
.write("charcoal1.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('1.png')
   
// Set stroke color
.stroke("#fe1232")
   
// Set fill color
.fill("#1200ff")
   
// Draw Rectangle using drawRectangle function
.drawRectangle(10, 2, 130, 30, 1, 2)
   
//Invoke Charcoal function as factor 3
.charcoal(3)
   
// Process and Write the image
.write("charcoal2.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.