Node.js GM drawRectangle() Function
The drawRectangle() function is an inbuilt function in the GraphicsMagick library which is used to draw a rectangle with specified coordinates. The function returns the true value of success.
Syntax:
drawRectangle( x0, y0, x1, y1, wc, hc )
Parameters: This function accepts six parameters as mentioned above and described below:
- x0: It holds the first x-coordinate of the rectangle.
- y0: It holds the first y-coordinate of the rectangle.
- x1: It holds the second x-coordinate of the rectangle.
- y1: It holds the second y-coordinate of the rectangle.
- wc: It is an optional parameter that holds the roundness of the width.
- hc: It is an optional parameter that holds the roundness of the height.
Return Value: This function returns the GraphicsMagick object.
Example 1: Without optional parameters
javascript
const gm = require( 'gm' );
gm(600, 300, 'white' )
.stroke( "green" , 3)
.font( "Helvetica.ttf" , 60)
.drawRectangle(10, 100, 260, 210)
.drawText(150, 170, "1" )
.drawRectangle(260, 100, 350, 210)
.drawText(300, 170, "2" )
.drawText(100, 280, "GeeksforGeeks!" )
.write( "drawRectangle1.png" , function (err) {
if (!err) console.log( 'done' );
});
|
Output:
Example 2: With the use of optional parameters
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!" )
.write( "drawRectangle1.png" , function (err) {
if (!err) console.log( 'done' );
});
|
Output:
Reference:
Last Updated :
29 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...