Created
July 8, 2015 02:02
-
-
Save danmactough/5d6f8bb7ec9383facb20 to your computer and use it in GitHub Desktop.
Not using this really clever bit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function () { | |
actions.zoomForPrint(); | |
window.requestAnimationFrame(function () { | |
const imgData = getImageFromCanvas(); | |
// atob to base64_decode the data-URI | |
const imgSrc = atob(imgData.split(",")[1]); | |
// Use typed arrays to convert the binary data to a Blob | |
const buffer = new ArrayBuffer(imgSrc.length); | |
var view = new Uint8Array(buffer); | |
for (var i = 0; i < imgSrc.length; i++) { | |
view[i] = imgSrc.charCodeAt(i) & 0xff; | |
} | |
var blob = new Blob([buffer], { type: "application/octet-stream" }); | |
// Use the URL object to create a temporary URL | |
var url = window.URL.createObjectURL(blob); | |
// Download | |
location.href = url; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment