image-filter-core

    2.0.2 • Public • Published

    build status Dependency Status npm version codecov

    image-filter-core

    Small library that relies on webworkers to apply image transformations.

    There are several modules that use image-filter-core, such as:

    But you can easily create your own transformation function and rely on image-filter-core to handle the webworkers and to split the work.

    Install

    npm install image-filter-core --save
    

    Methods

    # getCanvas()

    It returns a canvas with the given width and height

    var imageFilterCore = require('image-filter-core');
    var canvas = imageFilterCore.getCanvas(100, 100);

    # convertImageDataToCanvasURL()

    Given a ImageData it returns the dataURL

    var imageFilterCore = require('image-filter-core');
    var canvasURL = imageFilterCore.convertImageDataToCanvasURL(imageData);

    # apply()

    Provide the ImageData, the transformation function, the options to be passed to the transformation function and the number of workers to split the work.

    var imageFilterCore = require('image-filter-core');
     
    imageFilterCore.apply(data, transform, options, nWorkers)
        .then(function (imageData) {
            // Do whatever you want with imageData
        });

    The transform function receives ImageData, the length of data to transform and the options that the developer provided to image-fiter-core, example transformation function for the threshold effect:

    function transform (data, length, options) {
        for (var i = 0; i < length; i += 4) {
            var r = data[i];
            var g = data[+ 1];
            var b = data[+ 2];
            var v = (0.2126 * r + 0.7152 * g + 0.0722 * b >= options.threshold) ? 255 : 0;
            data[i] = data[+ 1] = data[+ 2] = v;
        }
    }

    Install

    npm i image-filter-core

    DownloadsWeekly Downloads

    158

    Version

    2.0.2

    License

    ISC

    Last publish

    Collaborators

    • canastro