Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js GM rotate() Function

  • Last Updated : 13 Oct, 2021

The rotate() function is an inbuilt function in the GraphicsMagick library which is used to rotate the image by specified angle. The function returns the true value on success.

Syntax:

rotate( angle, color )

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

  • angle: This parameter stores the value of the angle.
  • color: This parameter stores the value of the color as string which is to be set as background color.

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('gfg.png')
  
// Invoke rotate function with background
// color as #545651 and rotation angle as
// 78 Degrees clockwise.
.rotate("#545651", 78)
  
// Process and Write the image
.write("rotate1.png", function (err) {
  if (!err) console.log('done');
});

Output:

Example 2:




// Include gm library
var gm = require('gm');
  
// Import the image
gm('gfg.png')
  
// Set stroke color
.stroke("#fe1232")
  
// Set fill color
.fill("#1200ff")
  
// Draw Rectangle using drawRectangle function
.drawRectangle(10, 2, 130, 30, 1, 2)
  
//Invoke Sharpen Function with radius as 10 
.sharpen(10, 4)
  
// Invoke rotate function with background
// color as #67f123 and rotation angle as
// 45 Degrees clockwise.
.rotate("#67f123", 45)
  
// Process and Write the image
.write("rotate2.png", function (err) {
    if (!err) console.log('done');
});

Output:

Reference:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!