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


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

negative() 函數是 GraphicsMagick 庫中的內置函數,用於將每個像素替換為其補色。該函數成功時返回真實值。

用法:

negative()

參數:該函數不接受任何參數。

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

示例 1:

javascript


// Include gm library
const gm = require('gm');
// Import the image and invoke the negative the function
gm('1.png').negative()
// Process and Write the image
.write("negative1.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 borderColor() function
// and set border color to green
.borderColor("Green")
// Invoke border function
.border(62, 32)
// Invoke negative function
.negative()
// Process and write the image 
.write("negative2.png", function (err) {
      if (!err) console.log('done');
});

輸出:

示例 3:

javascript


// Include gm library
const gm = require('gm');
gm('1.png')
// Include another image
.composite('operator-noise-multiplicative1.png')
// Shift the image using geometry function
.geometry('+10+50')
// Invoke compose function with 'plus' Argument
.compose('plus')
// Include another image
.composite('randomThreshold1.png')
// Shift the image using geometry function
.geometry('+20+70')
// Invoke compose function with 'plus' argument
.compose('plus')
// Invoke negative function
.negative()
// Process and write the image
.write('negative3.png', function(err) {
    if(!err) console.log("Written composite image.");
});

輸出:

參考:



相關用法


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