Node.js GM drawLine() Function
The drawLine() function is an inbuilt function in the GraphicsMagick library which is used to draw the line with specified coordinates. The function returns the true value of success.
Syntax:
drawLine( x0, y0, x1, y1 )
Parameters: This function accepts four parameters as mentioned above and described below:.
- x0: This parameter stores the x-coordinate value of the initial point.
- y0: This parameter stores the y-coordinate value of the initial point.
- x1: This parameter stores the x-coordinate value of the final point.
- y1: This parameter stores the y-coordinate value of the final point.
Return Value: This function returns the GraphicsMagick object.
Original Image:
Example 1:
javascript
const gm = require( 'gm' ).subClass({imageMagick: true });
gm( '1.png' )
.stroke( "#000000" , 20)
.drawLine(100, 30, 400, 80)
.write( "drawLine1.png" , function (err) {
if (!err) console.log( 'done' );
});
|
Output:
Example 2:
Javascript
const gm = require( 'gm' );
gm(600, 300, 'white' )
.stroke( "green" , 3)
.font( "Helvetica.ttf" , 60)
.drawLine(100, 45, 100, 200)
.drawLine(100, 45, 500, 45)
.drawLine(500, 45, 500, 200)
.drawText(100, 280, "GeeksforGeeks!" )
.write( "drawLine1.png" , function (err) {
if (!err) console.log( 'done' );
});
|
Output:
Reference:
Last Updated :
30 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...