diff options
author | Orangerot <purple@orangerot.dev> | 2024-12-07 20:24:16 +0100 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-12-07 20:24:16 +0100 |
commit | 4ec96e68d137614172c86d162adfa6f676b0eef9 (patch) | |
tree | 0e9e14a3dae4d32f6968a1fd1fc76a2b62439199 /main.js | |
parent | 686e314d6a554c1a73a18438b0219207c97b470d (diff) |
feat: download canvas image
Diffstat (limited to 'main.js')
-rw-r--r-- | main.js | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -6,6 +6,10 @@ document.addEventListener("DOMContentLoaded", function () { document.getElementById("take-picture").addEventListener("click", take_picture); document.getElementById("upload-image").addEventListener("change", upload_image) + + document.getElementById("save").addEventListener("click", save_image) + document.getElementById("share").addEventListener("click", share_image) + canvas = document.getElementById("myCanvas"); imports = document.getElementById("imports"); }) @@ -31,4 +35,15 @@ function upload_image(event) { } } +function save_image() { + const dataUrl = canvas.toDataURL("image/png"); + // downloading only works with links but not window.open + const link = document.createElement('a'); + link.href = dataUrl; + link.download = 'imagine.png'; + link.click(); +} + +function share_image() { +} |