Skip to content
Related Articles

Related Articles

Improve Article

Node.js | GM stroke() Function

  • Last Updated : 14 Jan, 2020

The stroke() function is an inbuilt function in GraphicsMagick library which is used to set the color and width of the stroke used to draw object outlines.

Syntax:

stroke( color, width )

Parameters: This function accept two parameters as mentioned above and described below:

  • color: This parameter stores the color of the stroke.
  • width: This is an optional parameter which stores the width of the object.

Return Value: This function returns GraphicsMagick object with image added.

Original Image:



Example 1:




// Include gm library
var gm = require('gm');
  
// Import the image
gm('1.png')
  
// Set stroke color and size
.stroke("#fe1232", 5)
  
// Set fill color
.fill("#56f864")
  
// Draw Circle using drawCircle function
.drawCircle(120, 50, 100, 60).stroke()
  
// Process and Write the image
.write("1a.png", function (err) {
    if (!err) console.log('done');
});

Output:

Example 2:
Original Image:

Program:




// Include gm library
var gm = require('gm');
  
// Import the image
gm('1.png')
  
// Set stroke color
.stroke("#fe1232")
  
// Set fill color
.fill("#1200ff")
  
// Draw Rectangle using drawRectangle function
.drawRectangle(10, 2, 130, 30, 1, 2)
  
// Process and Write the image
.write("1a.png", function (err) {
    if (!err) console.log('done');
});

Output:

Reference:




My Personal Notes arrow_drop_up
Recommended Articles
Page :