Skip to content
Related Articles

Related Articles

Nodejs | GM transparent() Function
  • Last Updated : 13 Mar, 2020
GeeksforGeeks - Summer Carnival Banner

The transparent() function is an inbuilt function in the GraphicsMagick library which is used to make the specified color as transparent within the image. The function returns the true value on success.

Syntax:

transparent( color )

Parameters: This function accepts 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:




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

Output:

Example 2: Overwritting the file.




// Include gm library
var gm = require('gm');
  
// Import the image
gm(600, 300, 'white')
  
// Set the color for the stroke
.stroke("green", 3)
  
// Set the font 
.font("Helvetica.ttf", 60)
  
// Invoke drawRectangle function with x0: 10,
// y0: 100, x1:260, y1:210, wc: 40, wh: 40
.drawRectangle(10, 100, 260, 210, 40, 40)
  
// Invoke drawText in order to name the box as 1 
.drawText(150, 170, "1")
  
// Invoke drawrectangle function with x0: 260,
// y0:100, x1: 350, y1: 210, wc: 80, wh: 80
.drawRectangle(260, 100, 350, 210, 80, 80)
  
// Invoke drawText in order to name the box as 2
.drawText(300, 170, "2")
  
// Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
  
// Invoke trasparent function on green color
.transparent('green')
  
// Process and write the image 
.write("transparent2.png", function (err) {
  if (!err) console.log('done');
});

Output:

Reference:

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :