Open In App

Node.js GM sharpen() Function

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

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:

  • radius: This parameter stores the radius value of the sharpness.
  • sd: It is an optional parameter that stores the standard deviation of the image.

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

Original Image: 

 

Example 1: 

javascript




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

javascript




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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads