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,6 +170,7 @@ goog.require('goog.Timer'); ...@@ -170,6 +170,7 @@ goog.require('goog.Timer');
var a = document.createElement('a'); var a = document.createElement('a');
a.download = name; a.download = name;
a.target = "_blank"; a.target = "_blank";
if (canvas.toBlob === undefined) {
var src = canvas.toDataURL('image/png'); var src = canvas.toDataURL('image/png');
a.href = src; a.href = src;
document.body.appendChild(a); document.body.appendChild(a);
...@@ -177,6 +178,16 @@ goog.require('goog.Timer'); ...@@ -177,6 +178,16 @@ goog.require('goog.Timer');
a.parentNode.removeChild(a); a.parentNode.removeChild(a);
}); });
a.click(); 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 () { image.onerror = function () {
console.log("Error") 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