Node.js GM drawPolyline()函数
drawPolyline()函数是 GraphicsMagick 库中的一个内置函数,用于绘制具有指定坐标的折线。该函数在成功时返回真值。
句法:
drawPolyline( [x0, y0], ..., [xn, yn] )
参数:此函数接受 x 和 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("#000000")
// Invoke drawPolyline function with array of points
.drawPolyline([12, 60], [45, 79], [80, 120], [300, 32])
// Process and write the image
.write("drawPolyline1.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 drawPolyline function with
// array of points
.drawPolyline([12, 60], [45, 79], [80, 120],
[300, 32], [400, 150], [500, 200])
// Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Process and write the image
.write("drawPolyline1.png", function (err) {
if (!err) console.log('done');
});
输出:
参考:
- http://www.graphicsmagick.org/GraphicsMagick.html#details-draw
- https://www.npmjs.com/package/gm