Open In App

Node.js GM sharpen() Function

The sharpen() function is an inbuilt function in the GraphicsMagick library which is used to sharpen the image. It uses a Gaussian operator of the given radius and standard deviation (sigma). 

Syntax:



sharpen( radius, sd )

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

Return Value: This function returns Gmagick to sharpen the image. 



Original Image: 

 

Example 1: 




// Include gm library
const gm = require('gm');
 
// Import the image
gm('1.png')
 
// Invoke sharpen function with
// radius as 10 ad standard
// deviation as 2
.sharpen(10, 2)
 
// Process and Write the image
.write("1b.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 Sharpen Function with radius as 10
.sharpen(10)
 
// Process and Write the image
.write("1a.png", function (err) {
    if (!err) console.log('done');
})

Output:

  

Reference:


Article Tags :