drawLine()函數是GraphicsMagick庫中的內置函數,用於繪製具有指定坐標的線。成功時該函數返回真實值。
用法:
drawLine( 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("#000000", 20)
// Invoke drawLine function with x0 as 100,
// y0 as 45, x1 as 100, y1 as 89, r0 as 50
// and r1 as 40
.drawLine(100, 30, 400, 80)
// Process and write the image
.write("drawLine1.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 drawLine function with
// x0 as 100, y0 as 45, x1 as 100,
// y1 as 200
.drawLine(100, 45, 100, 200)
// Invoke drawLine function with
// x0 as 100, y0 as 45, x1 as 500,
// y1 as 45
.drawLine(100, 45, 500, 45)
// Invoke drawLine function with
// x0 as 500, y0 as 45, x1 as 500,
// y1 as 200
.drawLine(500, 45, 500, 200)
// Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Process and write the image
.write("drawLine1.png", function (err) {
if (!err) console.log('done');
});
輸出:
參考:
相關用法
- Node.js GM drawRectangle()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM drawPolygon()用法及代碼示例
- Node.js GM charcoal()用法及代碼示例
- Node.js GM drawEllipse()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 Nodejs | GM drawLine() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。