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'); ...@@ -170,13 +170,24 @@ 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";
var src = canvas.toDataURL('image/png'); if (canvas.toBlob === undefined) {
a.href = src; var src = canvas.toDataURL('image/png');
document.body.appendChild(a); a.href = src;
a.addEventListener("click", function(e) { document.body.appendChild(a);
a.parentNode.removeChild(a); a.addEventListener("click", function(e) {
}); 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