Node.js | GM trim() Function

The trim() function is an inbuilt function in the GraphicsMagick library which is used to remove edges that are exactly the same color as the corner pixels. The function returns the true value on success.

Syntax:

trim()

Parameters: This function does not accepts any parameters.

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

Original Image:



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Include gm library
var gm = require('gm');
  
// Import the image
gm('1.png')
  
// Invoke trim function 
.trim()
  
// Process and Write the image
.write("trim1.png", function (err) {
    if (!err) console.log('done');
});

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Include gm library
var 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 wave function with an amplitude
// as 8 and wavelength as 3
.wave(20, 30)
   
 // Invoke trim function 
.trim()
  
// Process and Write the image
.write("trim2.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.