Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Proper order of quality+toDataURL -> mozGetFile -> toDataURL #5

Closed
wants to merge 3 commits into from

2 participants

@rubenstolk

No description provided.

@blueimp
Owner

Thanks again for your contribution.
I've incorporated them in the latest commit which is a slightly different implementation: 578a203

@blueimp blueimp closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 9 deletions.
  1. +12 −9 canvas-to-blob.js
View
21 canvas-to-blob.js
@@ -71,15 +71,18 @@
return bb.getBlob(mimeString);
};
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
- if (CanvasPrototype.mozGetAsFile) {
- CanvasPrototype.toBlob = function (callback, type) {
- callback(this.mozGetAsFile('blob', type));
- };
- } else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
- CanvasPrototype.toBlob = function (callback, type, quality) {
- callback(dataURLtoBlob(this.toDataURL(type, quality)));
- };
- }
+ CanvasPrototype.toBlob = function (callback, type, quality) {
+ if(typeof(quality) === 'number') {
+ if (CanvasPrototype.toDataURL && dataURLtoBlob) {
+ return callback(dataURLtoBlob(this.toDataURL(type, quality)));
+ }
+ } else if (CanvasPrototype.mozGetAsFile) {
+ return callback(this.mozGetAsFile('blob', type));
+ } else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
+ return callback(dataURLtoBlob(this.toDataURL(type)));
+ }
+ throw 'The toBlob operation is not supported in this browser';
+ };
}
if (typeof define === 'function' && define.amd) {
define(function () {
Something went wrong with that request. Please try again.