Code Monkey home page Code Monkey logo

spark-filter's Introduction

Spark Filter

License: MIT PRs Welcome Netlify Status

Spark Filter is an Instagram-like image manipulation Web Application which is written in JavaScript and comes with pre-defined Instagram-like filters (with the same filter names and very similar effects).

Author : Sayan Maity

preview-img

Installation

Spark Filter only uses a minified JavaScript code which is available on the Release page.

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

Built with

  • Frontend: HTML, CSS, Javascript
  • Version Control: Git
  • Hosting: Netlify, Github Pages

Getting Bugs ?

Generally when the page loads, you would find difficulty in changing the filter of the images or even navigating through diffferent Demo Images given in the website. Actually this filterous library is a little buggy! So the only way to overcome this is to reload the page 2-3 times and try to navigate between the demo pictures.
After doing these actions also if you are facing issue, feel free to drop me a mail here.

Usage

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.

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.

Setup and Installation

Fork and Clone this project. Make sure you have git installed. On the terminal, navigate to your workspace directory and run it โ€‹

Contributing

Pull requests are encouraged โ€‹

Future Scope

  • UI part can be improved by adding some animations

spark-filter's People

Contributors

sayan-maity avatar

Stargazers

Ki-Jeong Kim avatar Carolina avatar Swapnil Sarkar avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.