Open In App

Node.js GM shave() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The shave() function is an inbuilt function in the GraphicsMagick library which is used to shave the image pixels from the edges which specifies the width of the region to be removed from both sides of the image and the height of the regions to be removed from top and bottom. 

Syntax:

shave(width, height, percentage)

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

  • width: This parameter stores the value of the width by which the image is to be shaved.
  • height: This parameter stores the value of the height by which the image is to be shaved.
  • percentage: This is an optional boolean parameter that stores the percentage if set to true otherwise pixels.

Return Value: This function returns the Gmagick object with the image added. 

Original Image:

  

Program: 

javascript




// Include gm library
const gm = require('gm');
 
// Import the image
gm('1.png')
 
// Invoke shave function
.shave(30, 40, true)
 
// Process and Write the image
.write("shave1.png", function (err) {
      if (!err) console.log('done');
});


Output:

  

Reference:


Last Updated : 29 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads