当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js GM drawCircle()用法及代码示例


drawCircle()函数是GraphicsMagick库中的内置函数,用于绘制具有指定坐标的Circle。成功时该函数返回真实值。

用法:

drawCircle( x0, y0, x1, y1 )

参数:该函数接受上述和以下所述的四个参数:



  • x0:此参数存储初始点的x坐标值。
  • y0:此参数存储初始点的y坐标值。
  • x1:此参数存储最终点的x坐标值。
  • y1:此参数存储终点的y坐标值。

返回值:此函数返回GraphicsMagick对象。

原始图片:

范例1:

// Include gm library 
var gm = require('gm').subClass({imageMagick:true}); 
  
// Import the image 
gm('1.png') 
  
// set the color for the stroke 
.stroke("#ffffff") 
  
// Invoke drawCircle function with 
// x0 as 30, y0 as 45, x1 as 300 
// and y1 as 89 
.drawCircle(30, 45, 300, 89) 
  
// Process and write the image  
.write("drawCircle1.png", function (err) { 
  if (!err) console.log('done'); 
});

输出:

范例2:

// Include gm library 
var gm = require('gm'); 
  
// Import the image 
gm(600, 300, 'white') 
  
// Set the color for the stroke 
.stroke("green", 3) 
  
// Set the font  
.font("Helvetica.ttf", 60) 
  
// Invoke drawCircle function with 
// x0 as 10, y0 as 145, x1 as 200 
// and y1 as 199 
.drawCircle(10, 145, 200, 199) 
  
// Call to drawText Function 
.drawText(100, 280, "GeeksforGeeks!") 
  
// Process and write the image  
.write("drawCircle1.png", function (err) { 
  if (!err) console.log('done'); 
});

输出:

参考:




相关用法


注:本文由纯净天空筛选整理自sarthak_ishu11大神的英文原创作品 Nodejs | GM drawCircle() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。