📜  节点吉普 |颜色去饱和

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

节点吉普 |颜色去饱和

介绍
去饱和修饰符是 Nodejs 中内置的颜色修饰符 | Jimp 将图像去饱和到给定数量,从 0 到 100。如果通过 100 数量,它将产生灰度图像。
句法:

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

范围:

  • value - 此参数存储要应用的黑暗量。它的取值范围为 0 – 100。

输入图像:

示例 1:

javascript
// 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 desaturate modifier
  image.color([{apply:'desaturate', params: [60]}])
  .write('desaturate1.png');
}
 
main();
  console.log("Image Processing Completed");


javascript
// 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 desaturate modifier
  image.color([{apply:'desaturate', params: [50]}],function(err){
    if (err) throw err;
  })
  .write('desaturate2.jpg');
}
 
main();
  console.log("Image Processing Completed");


输出:

示例 2:cb(可选参数)

javascript

// 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 desaturate modifier
  image.color([{apply:'desaturate', params: [50]}],function(err){
    if (err) throw err;
  })
  .write('desaturate2.jpg');
}
 
main();
  console.log("Image Processing Completed");

输出:

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