Coder Social home page Coder Social logo

justjake / filter.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aprasad91/filter.js

0.0 3.0 1.0 4.12 MB

Image Processing Lib. in Javascript and HTML5 Canvas

Home Page: http://nikos-web-development.netai.net/

Shell 0.10% JavaScript 91.04% Python 8.86%

filter.js's Introduction

FILTER.js

A Javascript Library for Image Processing and Filtering using HTML5 Canvas

This is a library for filtering images in javascript using canvas element. It defines an Image class which represents and Image and 4 basic filters

  • ColorMatrixFilter (analogous to the actionscript version)
  • ConvolutionMatrixFilter (analogous to the actionscript version)
  • DisplacementMapFilter (analogous to actionscript version)
  • Image Blending Modes (analogous to Photoshop blends)

each basic filter is generic but it also includes basic filters like grayscale, colorize, threshold, gauss, laplace, emboss, etc.. also a SobelFilter is defined which is a composite filter (composition of generic filters)

source code, minified version and build tools are included also 2 examples are included a basic and an example with three.js

version 0.2

Author Nikos M.

URL http://nikos-web-development.netai.net/

URL http://workingclasscode.uphero.com/

Using Filters, Functionally

I've added a little something to keep you from pulling your hair out managing state across all your images: functional filters! Long live functional composition!

@TODO: move funcitonal features into the right place (right now they're just in examples/filters.html

with love from Jake Teton-Landis

Functional Filter Creation

You can easily make any filter into a function that returns a new image. see createFilterFunction. You pass createFilterFunction a filter class and (optionally) a function to apply to the new filter. This is useful to call instance methods on the filter. For example, the edge filter is created from the FILTER.ConvolutionMatrixFilter class by applying the instance method filter_instance.edge4(). To create an edge4 filter as a function:

var edgeFilter = createFilterFunction(FILTER.ConvolutionMatrixFilter,
    function() { this.edge4(); });

DOM Node Replacement

The only bother with producing images via functional composition is getting your new, multi-filtered image back into the DOM, and then being able to do that over and over. Luckily, I implemented a class to help out here: the DOMref. DOMrefs hold a place in the DOM and let you replace it over and over again.

// a picture of che
var im1 = new FILTER.Image('che.jpg');

// create a DOMref with the original canvas element:
var image_that_will_be_replaced = new DOMref(canvas_from_image(im1);

// replace it with a edge-filtered version
image_that_will_be_replaced.replace_with(canvas_from_image(
    edgeFilter(im1)));

Oh, canvas_from_image(im1) is just a function that returns a HTMLCanvasElement from a FILTER.Image. It is interchangable with im1.canvasElement, but I find it makes more sense in a function-composition context.

Have fun!

filter.js's People

Contributors

justjake avatar evantlee avatar aprasad91 avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

evantlee

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.