Node.js 通用 drawEllipse()函数
drawEllipse()函数是 GraphicsMagick 库中的一个内置函数,用于绘制具有指定坐标的椭圆。该函数在成功时返回真值。
句法:
drawEllipse( x0, y0, x1, y1, r0, r1 )
参数:此函数接受上面提到的六个参数,如下所述:。
- x0:该参数存储初始点的x坐标值。
- y0:该参数存储初始点的y坐标值。
- x1:此参数存储最终点的x坐标值。
- y1:此参数存储最终点的y坐标值。
- r0:此参数存储椭圆的 x 半径值。
- r1:此参数存储椭圆的 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 drawEllipse function with
// x0 as 230, y0 as 45, x1 as 100,
// y1 as 89, r0 as 50 and r1 as 40
.drawEllipse(230, 45, 300, 89, 50, 40)
// Process and write the image
.write("drawEllipse1.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)
//Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Invoke drawEllipse function with x0
// as 230, y0 as 45, x1 as 100, y1 as
// 89, r0 as 50 and r1 as 40
.drawEllipse(290, 15, 300, 210, 20, 160)
// Process and write the image
.write("drawEllipse1.png", function (err) {
if (!err) console.log('done');
});
输出:
参考:
- http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
- https://www.npmjs.com/package/gm