📜  节点吉普 |颜色异或

📅  最后修改于: 2022-05-13 01:56:44.033000             🧑  作者: Mango

节点吉普 |颜色异或

介绍
xor修饰符是 Nodejs 中内置的颜色修饰符 | Jimp 将两种颜色视为位域,并对给定图像的红色、绿色和蓝色分量应用 XOR 运算。

image.color([
  { apply: 'xor', params: value }
]);

范围:

  • value – 此参数存储要应用 xor 操作的颜色。

输入图像:

示例 1:

// npm install --save jimp
// import jimp library to the environment
var Jimp = require('jimp');
  
// User-Defined Function to read the images
async function main() {
  const image = await Jimp.read
('https://media.geeksforgeeks.org/wp-content/uploads/20190328185307/gfg28.png');
// color function having xor modifier
  image.color([{apply:'xor', params: ['green']}])
  .write('xor1.png');
} 
  
main();
  console.log("Image Processing Completed");

输出:

示例 2:cb(可选参数)

// npm install --save jimp
// import jimp library to the environment
var Jimp = require('jimp');
  
// User-Defined Function to read the images
async function main() {
  const image = await Jimp.read
('https://media.geeksforgeeks.org/wp-content/uploads/20190328185333/gfg111.png');
// color function having xor modifier
  image.color([{apply:'xor', params: ['blue']}], function(err){
    if (err) throw err;
  })
  .write('xor2.png');
}
  
main();
  console.log("Image Processing Completed");

输出:

参考: https://www.npmjs.com/package/jimp