📜  节点Jimp |彩色灰度

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

节点Jimp |彩色灰度

介绍
灰度修饰符是 Nodejs 中的内置颜色修饰符 | Jimp 根据给定的数量(从 0 到 100)将图像颜色去饱和度为灰度。
句法:

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

范围:

  • value – 此参数存储要应用的灰度量。它采用 0 – 100 之间的值。

输入图像:

示例 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 greyscale modifier
  image.color([{apply:'greyscale', params: [50]}])
  .write('greyscale1.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 greyscale modifier
  image.color([{apply:'greyscale', params: [50]}], function(err){
    if (err) throw err;
  })
  .write('greyscale2.png');
}
  
main();
  console.log("Image Processing Completed");

输出:

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