Coder Social home page Coder Social logo

isabella232 / javascript-canvas-to-blob Goto Github PK

View Code? Open in Web Editor NEW

This project forked from naptha/javascript-canvas-to-blob

0.0 0.0 0.0 197 KB

JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.

Home Page: http://blueimp.github.io/JavaScript-Canvas-to-Blob/test/

javascript-canvas-to-blob's Introduction

JavaScript Canvas to Blob

Description

Canvas to Blob is a polyfill for the standard JavaScript canvas.toBlob method.

It can be used to create Blob objects from an HTML canvas element.

Usage

Include the (minified) JavaScript Canvas to Blob script in your HTML markup:

<script src="js/canvas-to-blob.min.js"></script>

Then use the canvas.toBlob() method in the same way as the native implementation:

var canvas = document.createElement('canvas'); 
/* ... your canvas manipulations ... */
if (canvas.toBlob) {
    canvas.toBlob(
        function (blob) {
            // Do something with the blob object,
            // e.g. creating a multipart form for file uploads:
            var formData = new FormData();
            formData.append('file', blob, fileName);
            /* ... */
        },
        'image/jpeg'
    );
}

Requirements

The JavaScript Canvas to Blob function has zero dependencies.

However, Canvas to Blob is a very suitable complement to the JavaScript Load Image function.

API

In addition to the canvas.toBlob polyfill, the JavaScript Canvas to Blob script provides one additional function called dataURLtoBlob, which is added to the global window object if no AMD loader is used to load the script:

// 80x60px GIF image (color black, base64 data):
var b64Data = 'R0lGODdhUAA8AIABAAAAAP///ywAAAAAUAA8AAACS4SPqcvtD6' +
        'OctNqLs968+w+G4kiW5omm6sq27gvH8kzX9o3n+s73/g8MCofE' +
        'ovGITCqXzKbzCY1Kp9Sq9YrNarfcrvcLDovH5PKsAAA7',
    imageUrl = 'data:image/gif;base64,' + b64Data,
    blob = window.dataURLtoBlob && window.dataURLtoBlob(imageUrl);

Browsers

The following browsers support either the native or the polyfill canvas.toBlob() method:

Desktop browsers

Mobile browsers

  • Apple Safari Mobile on iOS 6.0+
  • Google Chrome on iOS 6.0+
  • Google Chrome on Android 4.0+

Test

JavaScript Canvas to Blob Test

License

The JavaScript Canvas to Blob script is released under the MIT license.

javascript-canvas-to-blob's People

Contributors

blueimp avatar hinathan avatar joewood 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.