• Stars
    star
    195
  • Rank 195,339 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Instagram-like photo manipulation library for Node.js and Javascript on browser

filterous-2

Filterous 2

Filterous 2 is an Instagram-like image manipulation library for Javascript and node.js.

This is a revamped version of Filterous, which was written for JavaScript for browser about 4 years ago. This version works on both Node.js and browser, and comes with pre-defined Instagram-like filters (with the same filter names and very similar effects).

Installation

For Node.js:

first, this module uses node-canvas, so you need Cairo and Pango. Please follow the installation guide here before started.

$ npm install filterous

For Browser:

<script src="filterous2.min.js"></script>

The minified JavaScript code is available on Release page.

Usage

The usages are slightly different for Node.js and the browser.

Basic Usage for Node.js

Import an image buffer to filterous then save to the disk.

const filterous = require('filterous');

filterous.importImage(buffer, options)
  .applyFilter(filter, value)
  .save(filename);

also:

filterous.importImage(buffer)
  .applyInstaFilter(filterName, options)
  .save(filename);

The applyFilter() can be used with other filters and the results are accumulative, while the predefined applyInstaFilter() overwrite the previous filter result. However you can use applyFilter() to adjust the colors after applyInstaFilter() is applied.

Options are:

{
  scale: <value>, 
  format: <imageFormat> 
}

The value must be less than 1. You can only scale down an image. and the imageFormat is either 'png', 'gif', or 'jpeg' (default).

Example for Node.js

Using color adjustment filters:

fs.readFile('input/leia.jpg', (err, buffer) => {
  if (err) throw err;
  let f = filterous.importImage(buffer)
    .applyFilter('brightness', 0.2)
    .applyFilter('colorFilter', [255, 255, 0, 0.05])
    .save('output/leia.jpg');
});

Example with predefined Instagram-like effects:

fs.readFile('input/leia.jpg', (err, buffer) => {
  let f = filterous.importImage(buffer, {scale: 0.5, format: 'png'})
    .applyInstaFilter('amaro')
    .save('output/leia.jpg');
});

Basic Usage for JavaScript on Browser

Import an image object to filterous and render as HTML with renderHtml.

filterous.importImage(imgObj, options)
  .applyFilter(filter, value)
  .renderHtml(imageDOM);

also:

filterous.importImage(imgObj, options)
  .applyInstaFilter(filterName)
  .renderHtml(imageDOM);
var imageDOM = document.querySelector('img.photo');
var imgObj = new Image();
imgObj.src = 'input/leia.jpg';

filterous.importImage(imgObj, options)
  .applyFilter('brightness', 0.2)
  .applyFilter('contrast', -0.3)
  .renderHtml(imageDOM);

Example with predefined Instagram-like effects:

filterous.importImage(imgObj, options)
  .applyInstaFilter(filterButton.id)
  .renderHtml(imageDOM);

Available Filter Effects and the Values

Most effects take a value (the amount of the effects) between -1 and 1. for example, the value for the brightness() 0 means unchanged, -1 darkens the image, and 1 means full-brightness. The image will turn almost completely white.

Effect Adjestment(s)
grayscale N/A
sepia 0 to 1
invert N/A
brightness -1 to 1
saturation -1 to 1
contrast -1 to 1
rgbAdjust [r, g, b]
colorFilter [r, g, b, adj] // adj is 0 to 1
convolute 3x3 matrix

Available InstaFilter Names

Names
normal clarendon gingham moon lark reyes
juno slumber crema ludwig aden perpetua
amaro mayfair rise hudson valencia xpro2
sierra willow lofi inkwell hefe nashville
stinson vesper earlybird brannan sutro toaster
walden 1977 kelvin maven ginza skyline
dogpatch brooklyn helena ashby charmes

Note: normal gives no filter effect. It normalize the image to the original.

Demo

Try the demo on browser!

Behind the Scene

Filterous takes an image into a canvas to manipulate the pixels of the image. Unlike the CSS filters that alters how the image appearance only on browsers, the JavaScript library actually alters the pixel color values. So you can actually download the modified image.

The CanvasRenderingContext.getImageData() method of the Canvas API returns an ImageData object representing the underlying pixel data of the canvas, and the data property of pixelData stores the color info of an each pixel in the canvas. (The diagram below shows a canvas size of only 9x9 pixel to make it simple).

Each pixel in the data array consists of 4 bytes values- red, green, blue, and alpha channel, and each of the R (red), G (green), B (blue) and A (alpha transparency) values can take values between 0 and 255.

canvas image manipulation

This library alters R, G, or B values of each pixel (yes, each pixel in the entire image! so the operation can be quite slow with JavaScript!) to get filtered look.

Browser Supports

Filterous 2 for browsers should support all the modern browsers that supports Promises.

Contribute

I am pretty sure this library is buggy. Please feel free to send me pull requests.

More Repositories

1

a-picture-is-worth-a-1000-words

I am trying to describe complex matters in simple doodles!
10,849
star
2

RPi-KittyCam

Raspberry Pi app using a camera and PIR motion sensor, written in Node.js with Johnny-Five and Kittydar for cat facial detection
JavaScript
582
star
3

web-speech-ai

Simple AI Chat Bot Demo with Web Speech API
JavaScript
362
star
4

Filterous

Instagram-like photo manipulation library in JavaScript
JavaScript
141
star
5

fb-apiai-bot-demo

A simple example of Facebook Chat Bot using API.ai
JavaScript
74
star
6

slack-httpstatuscats

HTTP Status Cats for Slack
JavaScript
47
star
7

html5-notifications-webOS-style

HTML5 Web Notifications API Demo
CSS
45
star
8

slack-sentiment

Slackbot: Sentiment analysis for Slack messages using IBM Watson
JavaScript
39
star
9

dash-rickroll

A node.js application to Rickroll whoever presses your Amazon Dash button.
JavaScript
36
star
10

x-barcode

Web Component wrapper for UPC-A (for now) barcode using Polymer.
HTML
22
star
11

girliemac.github.io

GirlieMac Blog on Github Pages
Less
18
star
12

arduino-led-rgb

A poor man's HUE smart light bulb demo with Arduino and RGB common cathode LED
CSS
18
star
13

send-sms

Nexmo demo: Sending SMS from web
JavaScript
17
star
14

presentation-slides

My Presentation slides in HTML
HTML
17
star
15

girliemac

my profile
11
star
16

magic8ball

HTML5 Device Orientation API Demo
JavaScript
9
star
17

msteams-httpstatuscats

HTTP Status Cats app for Microsoft Teams
JavaScript
8
star
18

nexmo-webhook

Nexmo Inbound Message Webhook Example in Node.js
JavaScript
5
star
19

sushi-compass

Pizza Compass Knock-off in HTML5
JavaScript
4
star
20

passport-uber-v2

Uber authentication strategy for Passport and Node.js
JavaScript
3
star
21

passport-lyft

Lyft authentication strategy for Passport and Node.js.
JavaScript
3
star
22

slack-twilio-call-demo

A Slack demo for Twilio Signal 2019 (1) receive a call and send a transcript to Slack and (2) Make a call to an agent and customer from Slack
JavaScript
3
star
23

Mojo-ICanHasLOL

ICanHasLOL app for Palm WebOS. (Unfinished. works as expected on emulator & devices. UI/Style will be modified. Icons will be modified.)
JavaScript
3
star
24

chat-lyft

A simple demo chat app that allows ypu to check nearby Lyft drivers
JavaScript
2
star
25

stickies

IndexedDB Demo App
JavaScript
2
star
26

comicsansfy

Make your web more friendly
2
star
27

x-twitter-button

Web Component wrapper for Twitter share button using Polymer
2
star
28

CoDoodler

Doodle with strangers on InterWeb
CSS
2
star
29

camera-cordova

PhoneGap version of the Coremob Camera app
JavaScript
1
star
30

flickr-css3-3d-demo

My CSS3 3D animation demo from 2009
CSS
1
star
31

terrarium-project

Learn the basics of HTML, CSS, and vanilla JavaScript DOM manipulation while building a web terrarium
HTML
1
star