Skip to content

Instantly share code, notes, and snippets.

@salzhrani
salzhrani / polyfill.js
Created March 27, 2015 13:33
canvas.toBlob polyfill
if( !HTMLCanvasElement.prototype.toBlob ) {
Object.defineProperty( HTMLCanvasElement.prototype, 'toBlob',
{
value: function( callback, type, quality )
{
var bin = atob( this.toDataURL( type, quality ).split(',')[1] ),
len = bin.length,
len32 = len >> 2,
a8 = new Uint8Array( len ),
a32 = new Uint32Array( a8.buffer, 0, len32 );