Nodejs | GM shave() Function

The shave() function is an inbuilt function in the GraphicsMagick library which is used to shave the image pixels from the edges which specify 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 which stores the percentage if set true otherwise pixels.

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

Original Image:



Program:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

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.