Code Monkey home page Code Monkey logo

canvas-to-tiff's Introduction

canvas-to-tiff

Converts a HTML5 canvas bitmap to a TIFF file (blob, data-uri, array) that can be saved on user's computer or transferred to server.

The TIFF file is standard compliant (baseline) and support RGB + alpha channel.

Features

  • Fast and small!
  • All operations are asynchronous and non-blocking
  • Supports alpha channel
  • Can convert Canvas to TIFF as ArrayBuffer
  • Can convert Canvas to TIFF as Blob
  • Can convert Canvas to TIFF as Data-URI
  • Saves in both big-endian (default) and little-endian (option) format
  • Arbitrary DPI for both X and Y directions can be set using options.
  • No dependencies
  • Documented source incl. HTML version (see docs/ folder)

Install

canvas-to-tiff can be installed in various ways:

Usage

canvas-to-tiff is easy to use. Just include the script in header or before the script section in your HTML file.

To convert the canvas to a TIFF file, call:

CanvasToTIFF.toDataURL(canvas, function(uri) {
    // uri is a Data-URI that can be used as source for images etc.
    // uri = "data:image/tiff;base64, ...etc...";
});

A faster option to Data-URIs is using Blobs:

CanvasToTIFF.toBlob(canvas, function(blob) {
    // blob object can be converted to an objectURL and then
    // set as source for images, or as download target:
    var url = URL.createObjectURL(blob);
});

For convenience, a direct Canvas to ObjectURL method is included:

CanvasToTIFF.toObjectURL(canvas, function(url) {
    // can be used as source for image or download target
});

To convert it to an ArrayBuffer that can be sent over the net:

CanvasToTIFF.toArrayBuffer(canvas, function(buffer) {
    // buffer is ArrayBuffer with the TIFF file
});

Setting an error handler (before calling other operations):

CanvasToTIFF.setErrorHandler(myErrorHandlerFunc);

NOTE: As with with ordinary canvas, cross-origin resource sharing (CORS) requirements must be fulfilled.

Issues

See the issue tracker for details.

License

Released under MIT license. You may use this class in both commercial and non-commercial projects provided that full header (minified and developer versions) is included.

© Epistemex 2015-2016

Epistemex

canvas-to-tiff's People

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.