节点 Jimp |颜色红色

原文:https://www.geeksforgeeks.org/node-jimp-color-red/

简介 红色修改器是 Nodejs | Jimp 中的一个内置颜色修改器,它以给定的量修改给定图像的红色分量。

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

参数:

  • –该参数存储图像红色的修改量。

输入图像:

例 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 red modifier
  image.color([{apply:'red', params: [73]}])
  .write('red1.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 red modifier
  image.color([{apply:'red', params: ['50']}], function(err){
    if (err) throw err;
  })
  .write('xor2.png');
}

main();
  console.log("Image Processing Completed");

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