节点吉普 |颜色变亮
简介:lighten 修饰符是 Nodejs 中内置的颜色修饰符 | Jimp 将图像的颜色变亮到给定的量,范围在 0 到 100 之间。如果提供 100,它将产生透明的白色图像。
句法:
image.color([
{ apply: 'lighten', params: [value] }
]);
范围:
- value – 此参数存储要应用的亮度量。它的取值范围为 0 – 100。
输入图像:
设置环境:
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');
// color function having lighten modifier
image.color([{apply:'lighten', params: [50]}])
.write('lighten1.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 lighten modifier
image.color([{apply:'lighten', params: [50]}], function(err){
if (err) throw err;
})
.write('lighten2.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');
// color function having lighten modifier
image.color([{apply:'lighten', params: [50]}], function(err){
if (err) throw err;
})
.write('lighten2.png');
}
main();
console.log("Image Processing Completed");
输出:
参考: https://www.npmjs.com/package/jimp