當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Node.js GM border()用法及代碼示例

border() 函數是 GraphicsMagick 庫中的內置函數,用於用顏色邊框包圍圖像。該函數成功時返回真實值。

用法:

border( width, height )

參數:該函數接受如上所述和如下所述的兩個參數:

  • width:該參數用於指定圖像周圍邊框的寬度。
  • height:該參數用於指定圖像周圍邊框的高度。

返回值:該函數返回GraphicsMagick對象。

示例 1:

javascript


// Include gm library
const gm = require('gm');
// Import the image
gm('1.png')
// Invoke border function with 10*40
.border(10, 40)
// Process and Write the image
.write("border1.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)
//Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
// Invoke border function with 62 * 32
.border(62, 32)
// Process and write the image 
.write("border2.png", function (err) {
      if (!err) console.log('done');
});

輸出:

參考:



相關用法


注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 Node.js GM border() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。