Skip to content

Commit

Permalink
Prefer toDataURL over mozGetAsFile if the quality parameter is supplied.
Browse files Browse the repository at this point in the history
Thanks again to rubenstolk for the contribution:
#5
  • Loading branch information
blueimp committed Nov 12, 2012
1 parent bef4f47 commit 578a203
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
10 changes: 7 additions & 3 deletions canvas-to-blob.js
@@ -1,5 +1,5 @@
/* /*
* JavaScript Canvas to Blob 2.0.4 * JavaScript Canvas to Blob 2.0.5
* https://github.com/blueimp/JavaScript-Canvas-to-Blob * https://github.com/blueimp/JavaScript-Canvas-to-Blob
* *
* Copyright 2012, Sebastian Tschan * Copyright 2012, Sebastian Tschan
Expand Down Expand Up @@ -72,8 +72,12 @@
}; };
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) { if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
if (CanvasPrototype.mozGetAsFile) { if (CanvasPrototype.mozGetAsFile) {
CanvasPrototype.toBlob = function (callback, type) { CanvasPrototype.toBlob = function (callback, type, quality) {
callback(this.mozGetAsFile('blob', type)); if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {
callback(dataURLtoBlob(this.toDataURL(type, quality)));
} else {
callback(this.mozGetAsFile('blob', type));
}
}; };
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) { } else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
CanvasPrototype.toBlob = function (callback, type, quality) { CanvasPrototype.toBlob = function (callback, type, quality) {
Expand Down
2 changes: 1 addition & 1 deletion canvas-to-blob.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ {
"name": "blueimp-canvas-to-blob", "name": "blueimp-canvas-to-blob",
"version": "2.0.4", "version": "2.0.5",
"title": "JavaScript Canvas to Blob", "title": "JavaScript Canvas to Blob",
"description": "JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.", "description": "JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.",
"keywords": [ "keywords": [
Expand Down

0 comments on commit 578a203

Please sign in to comment.