Node Jimp | постеризовать

Опубликовано: 6 Августа, 2021

Введение : функция posterize () - встроенная функция в Nodejs | Jimp, который применяет эффект постеризации с уровнем n.
Синтаксис:

 постеризовать (n, cb)

Параметр:

  • n - этот параметр хранит величину для регулировки контрастности, а минимальный порог равен двум.
  • cb - это необязательный параметр, который вызывается после завершения компиляции.

Входные изображения:

Шаг 1. Настройка среды

 npm init -y

Шаг 2: установите jimp

 npm установить jimp --save

Пример 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
// sepia function
image.posterize(4)
.write( 'posterize1.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
// opaque function using callback function
image.posterize(5, function (err){
if (err) throw err;
})
.write( 'posterize2.png' );
}
main();
console.log( "Image Processing Completed" );

Выход:

Ссылка: https://www.npmjs.com/package/jimp