📜  节点 |吉普 |对比

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

节点 |吉普 |对比

简介: contrast()函数是 Nodejs 中的内置函数| Jimp 通过 -1 到 +1 的值调整图像的对比度。

句法:

contrast(n, cb)

范围:

  • n – 此参数存储调整对比度的量,介于 -1 和 +1 之间的数字
  • cb – 这是编译完成时调用的可选参数。

输入图像:

设置环境:

npm init -y

安装依赖:

npm install jimp

示例 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');
// contrast function
  image.contrast(.4)
  .write('contrast1.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');
// contrast function using callback function
  image.posterize(.5, function(err){
    if (err) throw err;
  })
  .write('contrast2.png');
}
 
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');
// contrast function using callback function
  image.posterize(.5, function(err){
    if (err) throw err;
  })
  .write('contrast2.png');
}
 
main();
  console.log("Image Processing Completed");

输出:

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