download feature

This commit is contained in:
Vitaly Domnikov
2022-09-29 14:01:14 -07:00
parent f16fa3c5ae
commit c5f4a6056f
+23
View File
@@ -440,6 +440,7 @@
<section class="sub-section">
<button type="button" class="generate-button" onclick="outputString()">Generate code</button>
<button type="button" id = "copy-button" onclick="copyOutput()">Copy Output</button>
<button type="button" id = "copy-button" onclick="downloadFile()">Download as binary file</button>
<textarea id="code-output" class="code-output"></textarea>
</section>
</section>
@@ -1227,6 +1228,28 @@
navigator.clipboard.writeText(__output);
}
function downloadFile() {
raw = [];
images.each((image) => {
data = imageToString(image)
.split(',')
.map(s => s.trim())
.filter(Boolean)
.map((byte) => parseInt(byte, 16));
raw = raw.concat(data);
});
data = new Uint8Array(raw);
a = document.createElement("a");
a.style = "display: none";
document.body.appendChild(a);
blob = new Blob([data], {type: "octet/stream"});
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = getIdentifier() + ".bin";
a.click();
window.URL.revokeObjectURL(url);
}
// Use the horizontally oriented list to draw the image
function listToImageHorizontal(list, canvas){