Node.js GM transparent() Function
Last Updated :
30 Mar, 2023
The transparent() function is an inbuilt function in the GraphicsMagick library which is used to make the specified color transparent within the image. The function returns the true value of success.
Syntax:
transparent( color )
Parameters: This function accepts a single parameter as mentioned above and described below:
- color: This parameter is used to specify the name of the color.
Return Value: This function returns the GraphicsMagick object.
Original Image:
Example 1:
Javascript
const gm = require( 'gm' );
gm( '1.png' )
.transparent( 'white' )
.write( "transparent1.png" , function (err) {
if (!err) console.log( 'done' );
});
|
Output:
Example 2: Overwriting the file.
Javascript
const gm = require( 'gm' );
gm(600, 300, 'white' )
.stroke( "green" , 3)
.font( "Helvetica.ttf" , 60)
.drawRectangle(10, 100, 260, 210, 40, 40)
.drawText(150, 170, "1" )
.drawRectangle(260, 100, 350, 210, 80, 80)
.drawText(300, 170, "2" )
.drawText(100, 280, "GeeksforGeeks!" )
.transparent( 'green' )
.write( "transparent2.png" , function (err) {
if (!err) console.log( 'done' );
});
|
Output:
Reference:
Share your thoughts in the comments
Please Login to comment...