Support type and encoderOptions parameters in toBlob polyfill.
This commit is contained in:
parent
673408f5e1
commit
832fb65cf5
@ -3,12 +3,13 @@ Polyfill =
|
|||||||
@toBlob()
|
@toBlob()
|
||||||
toBlob: ->
|
toBlob: ->
|
||||||
return if HTMLCanvasElement::toBlob
|
return if HTMLCanvasElement::toBlob
|
||||||
HTMLCanvasElement::toBlob = (cb) ->
|
HTMLCanvasElement::toBlob = (cb, type='image/png', encoderOptions) ->
|
||||||
data = atob @toDataURL()[22..]
|
url = @toDataURL type, encoderOptions
|
||||||
|
data = atob url[url.indexOf(',')+1..]
|
||||||
# DataUrl to Binary code from Aeosynth's 4chan X repo
|
# DataUrl to Binary code from Aeosynth's 4chan X repo
|
||||||
l = data.length
|
l = data.length
|
||||||
ui8a = new Uint8Array l
|
ui8a = new Uint8Array l
|
||||||
for i in [0...l] by 1
|
for i in [0...l] by 1
|
||||||
ui8a[i] = data.charCodeAt i
|
ui8a[i] = data.charCodeAt i
|
||||||
cb new Blob [ui8a], type: 'image/png'
|
cb new Blob [ui8a], {type}
|
||||||
$.globalEval "HTMLCanvasElement.prototype.toBlob = (#{HTMLCanvasElement::toBlob});"
|
$.globalEval "HTMLCanvasElement.prototype.toBlob = (#{HTMLCanvasElement::toBlob});"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user