Skip to content

Commit 089a677

Browse files
committedApr 18, 2020
Use canvas.msToBlob if applicable.
Resolves #33.
1 parent 547f099 commit 089a677

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed
 

‎js/canvas-to-blob.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,28 @@
106106
})
107107
}
108108
} else if (CanvasPrototype.toDataURL && dataURLtoBlob) {
109-
CanvasPrototype.toBlob = function (callback, type, quality) {
110-
var self = this
111-
setTimeout(function () {
112-
callback(dataURLtoBlob(self.toDataURL(type, quality)))
113-
})
109+
if (CanvasPrototype.msToBlob) {
110+
CanvasPrototype.toBlob = function (callback, type, quality) {
111+
var self = this
112+
setTimeout(function () {
113+
if (
114+
((type && type !== 'image/png') || quality) &&
115+
CanvasPrototype.toDataURL &&
116+
dataURLtoBlob
117+
) {
118+
callback(dataURLtoBlob(self.toDataURL(type, quality)))
119+
} else {
120+
callback(self.msToBlob(type))
121+
}
122+
})
123+
}
124+
} else {
125+
CanvasPrototype.toBlob = function (callback, type, quality) {
126+
var self = this
127+
setTimeout(function () {
128+
callback(dataURLtoBlob(self.toDataURL(type, quality)))
129+
})
130+
}
114131
}
115132
}
116133
}

0 commit comments

Comments
 (0)
Please sign in to comment.