From 4ec96e68d137614172c86d162adfa6f676b0eef9 Mon Sep 17 00:00:00 2001 From: Orangerot Date: Sat, 7 Dec 2024 20:24:16 +0100 Subject: feat: download canvas image --- index.html | 14 +++++++------- main.js | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 10049a3..a3ada32 100644 --- a/index.html +++ b/index.html @@ -44,10 +44,10 @@

Imagine

Image Editor

- - @@ -59,7 +59,7 @@
@@ -68,7 +68,7 @@
@@ -77,7 +77,7 @@
@@ -95,10 +95,10 @@
- - diff --git a/main.js b/main.js index 95c0558..6953ee5 100644 --- a/main.js +++ b/main.js @@ -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() { +} -- cgit v1.2.3