Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/hg-pyun/node-image-filter
- Owner: hg-pyun
- License: mit
- Created: 2017-02-18T10:11:23.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-20T14:22:38.000Z (about 6 years ago)
- Last Synced: 2024-10-03T12:38:01.048Z (3 months ago)
- Topics: filter, image-processing, javascript, nodejs
- Language: JavaScript
- Homepage:
- Size: 277 KB
- Stars: 36
- Watchers: 4
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
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