Open In App

Node.js GM trim() Function

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

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 of success. 

Syntax:

trim()

Parameters: This function does not accept any parameters. 

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

Original Image: 

 

Example 1: 

javascript




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


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 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');
});


Output:

  

Reference:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads