drawPolygon()函數是GraphicsMagick庫中的內置函數,用於繪製具有指定坐標的多邊形。成功時該函數返回真實值。
用法:
drawPolygon( [x0, y0], ... ,[xn, yn] )
參數:此函數接受x和y坐標數組。
返回值:此函數返回GraphicsMagick對象。
範例1:
// Include gm library
var gm = require('gm');
// Import the image
gm(500, 200, 'white')
// Set the color for the stroke
.stroke("green", 3)
// Set font as 'Helvetica'
.font("Helvetica.ttf", 60)
// Use drawText() Function
.drawText(30, 160, "GeeksforGeeks!")
// Invoke drawPolygon function
// with array of points
.drawPolygon([12, 60], [45, 79],
[80, 120], [300, 32], [300, 98])
// Process and write the image
.write("drawPolygon1.png", function (err) {
if (!err) console.log('done');
});
輸出:
範例2:
// Include gm library
var gm = require('gm');
// Import the image
gm('https://media.geeksforgeeks.org/wp-content/uploads/20200227114541/1406-3.png')
// Set the color for the stroke
.stroke("#000000", 5)
// Invoke drawPolygon function with array of points
.drawPolygon([12, 60], [45, 79], [80, 120], [300, 32])
// Process and write the image
.write("drawPolygon1.png", function (err) {
if (!err) console.log('done');
});
輸出:
參考:
相關用法
- Node.js GM drawLine()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawEllipse()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawRectangle()用法及代碼示例
- Node.js GM charcoal()用法及代碼示例
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 Nodejs | GM drawPolygon() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。