Node.js GM swirl() Function

The swirl() function is an inbuilt function in the GraphicsMagick library which is used around the center of the image. The degrees specify the tightness of the swirl. 

Syntax:

swirl( angle )

Parameters: This function accepts a single parameter which is mentioned above and described below:

  • angle: This parameter stores the angle of the swirl.

Return Value: This function returns the GraphicsMagick swirl image. 

Original Image: 

 

Example 1: 

javascript




// Include gm library
const gm = require('gm');
  
// Import the image
gm('1.png')
  
// Invoke swirl function with
// an angle values as 45
.swirl(45)
  
// Process and Write the image
.write("swirl1.png", function (err) {
    if (!err) console.log('done');
});


Output:

  

Example 2: 

javascript




// Include gm library
const 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)
  
// Invoke swirl function with
// an angle value as -270
.swirl(-270)
  
// Process and Write the image
.write("swirl2.png", function (err) {
    if (!err) console.log('done');
});


Output:

  

Reference:

  • http://www.graphicsmagick.org/GraphicsMagick.html#details-swirl
  • https://www.npmjs.com/package/gm