Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hg-pyun/node-image-filter

Simple Image Filter for Node.js
https://github.com/hg-pyun/node-image-filter

filter image-processing javascript nodejs

Last synced: 3 months ago
JSON representation

Simple Image Filter for Node.js

Awesome Lists containing this project

README

        

# node-image-filter
[![npm](https://img.shields.io/npm/v/node-image-filter.svg)](https://www.npmjs.com/package/node-image-filter)
[![npm](https://img.shields.io/npm/dt/node-image-filter.svg)](https://www.npmjs.com/package/node-image-filter)
[![GitHub license](https://img.shields.io/github/license/hg-pyun/node-image-filter.svg)](https://github.com/hg-pyun/node-image-filter/blob/master/LICENSE)

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 receives result data. The data contains image buffer, type, width, height information.
Let's look at the example.

```javascript
const Filter = require('node-image-filter');

// express
app.use(function (req, res, next) {

let imagePath = path.join(__dirname, '../samples/cat.jpg');

Filter.render(imagePath, Filter.preset.invert, function (result) {
/* result format
{
data : stream,
type : 'jpg',
width : 1024,
height : 768
}
*/
result.data.pipe(fs.createWriteStream(`result.${result.type}`)); // save local
res.send('save filtered image');
})
});
```

### 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.
```javascript
const Filter = require('node-image-filter');

// filter list
Filter.preset.invert
Filter.preset.grayscale
Filter.preset.sepia
Filter.preset.brightness
```

### 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.

```javascript
// custom filter
let CustomInvertFilter = function (pixels) {
var data = pixels.data;
for(let i=0; i