Node.js GM write() Function
The write() function is an inbuilt function in the GraphicsMagick library which is used to write an image to a file. If a file already exists, then it will be overwritten. The function returns the true value of success.
Syntax:
write( filename )
Parameters: This function accepts single parameters as mentioned above and described below:
- filename: This parameter is used to specify the name of the file.
Return Value: This function returns the GraphicsMagick object.
Example 1:
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: 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!" )
.write( "drawRectangle1.png" , function (err) {
if (!err) console.log( 'done' );
});
|
Output:
Reference: https://www.npmjs.com/package/gm
Last Updated :
29 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...