Open In App

Node.js 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 of success. 

Syntax:



charcoal( factor )

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

Return Value: This function returns the Gmagick charcoal image. 



Original Image: 

 

Example 1: 




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

Output:

  

Example 2: 




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

Output:

  

Reference:


Article Tags :