drawRectangle()函數是GraphicsMagick庫中的內置函數,用於繪製指定坐標的矩形。該函數返回成功的真實值。
用法:
drawRectangle( x0, y0, x1, y1, wc, hc )
參數:該函數接受上麵提到的六個參數,如下所述:
- x0:它保存矩形的第一個 x 坐標。
- y0:它保存矩形的第一個 y 坐標。
- x1:它保存矩形的第二個 x 坐標。
- y1:它保存矩形的第二個 y 坐標。
- wc:它是一個可選參數,用於保存寬度的圓度。
- hc:它是一個可選參數,用於保存高度的圓度。
返回值:該函數返回GraphicsMagick對象。
示例 1:不帶可選參數
javascript
// Include gm library
const 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 drawRectangle function with
// x0: 10, y0: 100, x1:260, y1:210
.drawRectangle(10, 100, 260, 210)
// Invoke drawText in order to
// name the box as 1
.drawText(150, 170, "1")
// Invoke drawrectangle function with
// x0: 260, y0:100, x1: 350, y1: 210
.drawRectangle(260, 100, 350, 210)
// Invoke drawText in order to
// name the box as 2
.drawText(300, 170, "2")
// Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Process and write the image
.write("drawRectangle1.png", function (err) {
if (!err) console.log('done');
});
輸出:
示例 2:使用可選參數
javascript
// Include gm library
const 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 drawRectangle function with
// x0: 10, y0: 100, x1:260, y1:210,
// wc: 40, wh: 40
.drawRectangle(10, 100, 260, 210, 40, 40)
// Invoke drawText in order to name
// the box as 1
.drawText(150, 170, "1")
// Invoke drawrectangle function with
// x0: 260, y0:100, x1: 350, y1: 210,
// wc: 80, wh: 80
.drawRectangle(260, 100, 350, 210, 80, 80)
// Invoke drawText in order to
// name the box as 2
.drawText(300, 170, "2")
// Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Process and write the image
.write("drawRectangle1.png", function (err) {
if (!err) console.log('done');
});
輸出:
參考:
相關用法
- Node.js GM drawRectangle()用法及代碼示例
- Node.js GM drawEllipse()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawPolygon()用法及代碼示例
- Node.js GM despeckle()用法及代碼示例
- Node.js GM swirl()用法及代碼示例
- Node.js GM rotate()用法及代碼示例
- Node.js GM stroke()用法及代碼示例
- Node.js GM shade()用法及代碼示例
- Node.js GM trim()用法及代碼示例
- Node.js GM wave()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM charcoal()用法及代碼示例
- Node.js GM flip()用法及代碼示例
- Node.js GM flop()用法及代碼示例
- Node.js GM border()用法及代碼示例
- Node.js GM thumbnail()用法及代碼示例
- Node.js GM enhance()用法及代碼示例
- Node.js GM write()用法及代碼示例
- Node.js GM transparent()用法及代碼示例
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 Node.js GM drawRectangle() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。