Giter Site home page Giter Site logo

mcanthony / image-juggler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kirbysayshi/image-juggler

2.0 2.0 0.0 96 KB

Juggle pixel data between different web containers, like <img>, <canvas>, ImageData, File, ArrayBuffer, Blob, Array, etc.

JavaScript 100.00%

image-juggler's Introduction

image-juggler

The web has some nice image-processing capabilities, but the APIs are wildly inconsistent. Plus, some third party libraries want a canvas, others want an image. And if you need to read an image in, you need to know the intimacies of the File and Blob APIs.

Usage

Accept an image File via an <input> tag, and append it to the document as an Image.

var jug = require('image-juggler');

var img = document.createElement('img');

var input = document.querySelector('input[type="file"]');
input.addEventListener('change', function(e) {
  e.stopPropagation();
  var file = e.target.files[0];

  if (!file) {
    throw new Error('No file or invalid file was selected');
  }

  jug.fileToImage(file, img, function(err, img) {
    document.body.appendChild(img);
  })
}, false)

API

Each of the functions follow the format of function(input, opt_output, callback), where:

  • input: the thing coming in...
  • opt_output: if part of the signature, this element is used as the target container of the transform operation. For example, imageToCanvas(image, opt_canvas, cb) will use opt_canvas, but if none is passed in it will create a new <canvas> and supply it to the callback. Supplying an existing element can help to avoid GC. Some operations, due to the underlying implementation, require a new object to be created regardless (such as ArrayBuffers).
  • callback: Always of the signature: function(error, result), even if the underlying operation is not asynchronous. NOTE: There is no guarantee that callback will be called asynchronously. Yes. This releases Zalgo.

imageToCanvas(image, opt_canvas, cb)

imageToArrayBuffer(image, cb)

imageDataToImage(imageData, opt_image, cb)

fileToArrayBuffer(file, cb)

fileToImage(file, opt_image, cb)

canvasToImage(canvas, opt_image, cb)

blobToImage(blob, opt_image, cb)

image-juggler's People

Contributors

kirbysayshi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.