node-image-filter
Image Processing Library for nodejs.
Install
$ npm install node-image-filter --save
Basic Usage
Render
To apply a filter, use the render function.
render(imagePath, filter[, options], callback);
You can use preset filters or custom filters. callback function receive result data. The data contains image buffer, type, width, height information. Let's look at the example.
const Filter = ; // expressapp;
Preset Filters
'node-image-filter' includes Preset filters. There are currently four filters in total. You just need to pass it as the second parameter of the Render function.
const Filter = ; // filter listFilterpresetinvertFilterpresetgrayscaleFilterpresetsepiaFilterpresetbrightness
Custom Filter
You can also use your own filters. Pass the filter you created yourself as the second parameter. The filter function takes pixels as a parameter and must process these pixels.data and return.
// custom filterlet { var data = pixelsdata; forlet i=0; i<datalength; i+=4 datai = 255 - datai; datai+1 = 255 - datai+1; datai+2 = 255 - datai+2; datai+3 = 255; return data;}; Filter
If you want to pass options to a filter, Use the third parameter of the Render function.
// custom filter with options{ var data = pixelsdata; var value = optionsvalue || 5; forvar i =0; i< datalength; i+=4 datai += value; datai+1 += value; datai+2 += value; return data;} // third param for option.let options = value : 10; Filter
Convolution
Render
You can also use convolution theory such as sobel, sharpen, and others. Here are some examples.
// sobelFilter // sharpenFilter // blurlet options = value : 100; Filter
Custom Convolution Filter
The usage is very similar to the custom filter. You can make convolution filter using Filter.convolution(pixels, weights, opaque)
.
Also, You pass option using third parameter.
{ return Filter;} Filter;
LICENSE
Copyright (c) 2017 Haegul, PYUN
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.