Skip to content

Commit 578a203

Browse files
committed
Prefer toDataURL over mozGetAsFile if the quality parameter is supplied.
Thanks again to rubenstolk for the contribution: blueimp#5
1 parent bef4f47 commit 578a203

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

canvas-to-blob.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Canvas to Blob 2.0.4
2+
* JavaScript Canvas to Blob 2.0.5
33
* https://github.com/blueimp/JavaScript-Canvas-to-Blob
44
*
55
* Copyright 2012, Sebastian Tschan
@@ -72,8 +72,12 @@
7272
};
7373
if (window.HTMLCanvasElement && !CanvasPrototype.toBlob) {
7474
if (CanvasPrototype.mozGetAsFile) {
75-
CanvasPrototype.toBlob = function (callback, type) {
76-
callback(this.mozGetAsFile('blob', type));
75+
CanvasPrototype.toBlob = function (callback, type, quality) {
76+
if (quality && CanvasPrototype.toDataURL && dataURLtoBlob) {
77+
callback(dataURLtoBlob(this.toDataURL(type, quality)));
78+
} else {
79+
callback(this.mozGetAsFile('blob', type));
80+
}
7781
};
7882
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
7983
CanvasPrototype.toBlob = function (callback, type, quality) {

canvas-to-blob.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-canvas-to-blob",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"title": "JavaScript Canvas to Blob",
55
"description": "JavaScript Canvas to Blob is a function to convert canvas elements into Blob objects.",
66
"keywords": [

0 commit comments

Comments
 (0)