Skip to content

Commit

Permalink
poly fill for toBlob()
Browse files Browse the repository at this point in the history
  • Loading branch information
hrj committed Jun 26, 2016
1 parent 089cb03 commit 322140b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/flif-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ document.addEventListener("DOMContentLoaded", function() {
});
}

// Poly-fill for toBlob, inspired by MDN docs
if (!HTMLCanvasElement.prototype.toBlob) {
Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', {
value: function (callback, type, quality) {

var binStr = atob(this.toDataURL(type, quality).split(',')[1] ),
len = binStr.length,
arr = new Uint8Array(len);

for (var i=0; i<len; i++ ) {
arr[i] = binStr.charCodeAt(i);
}

callback( new Blob( [arr], {type: type || 'image/png'} ) );
}
});
}

var canvasElements = document.querySelectorAll("canvas[data-polyflif-src]");
for (var i = 0; i < canvasElements.length; i++) {
process(canvasElements[i]);
Expand Down

0 comments on commit 322140b

Please sign in to comment.