Use a blob to export the blocks area as an Image

Apparently the canvas.toDataURL method does not work reliably when the
blocks image is large. Instead convert it to a block with canvas.toBlob
and create a URL from the blob. This seems to work with blocks areas
that fail with the toDataURL approach.

Change-Id: I8706c91c23e1522be193f5391afb6390ea036f81
parent 5c573951
......@@ -170,13 +170,24 @@ goog.require('goog.Timer');
var a = document.createElement('a');
a.download = name;
a.target = "_blank";
var src = canvas.toDataURL('image/png');
a.href = src;
document.body.appendChild(a);
a.addEventListener("click", function(e) {
a.parentNode.removeChild(a);
});
a.click();
if (canvas.toBlob === undefined) {
var src = canvas.toDataURL('image/png');
a.href = src;
document.body.appendChild(a);
a.addEventListener("click", function(e) {
a.parentNode.removeChild(a);
});
a.click();
} else {
canvas.toBlob(function(blob) {
a.href = URL.createObjectURL(blob);
document.body.appendChild(a);
a.addEventListener("click", function(e) {
a.parentNode.removeChild(a);
});
a.click();
});
}
}
image.onerror = function () {
console.log("Error")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment