summaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2024-12-12 01:18:06 +0100
committerOrangerot <purple@orangerot.dev>2024-12-12 01:18:06 +0100
commit313142d111111f69764b6eb07e4041a71c7d322a (patch)
tree66425dac40fcf8a57af2345b24b70ed72daa1483 /main.js
parentf08b0b4d51f1ba0f003cd9bffd6b481a92ae52de (diff)
feat: share image
Diffstat (limited to 'main.js')
-rw-r--r--main.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/main.js b/main.js
index 378e716..397cfa9 100644
--- a/main.js
+++ b/main.js
@@ -97,7 +97,8 @@ function upload_image() {
img.onload = () => draw(true);
}
-function save_image() {
+function save_image(event) {
+ event.preventDefault();
draw(false);
const dataUrl = canvas.toDataURL("image/png");
@@ -108,8 +109,23 @@ function save_image() {
link.click();
}
-function share_image() {
+function share_image(event) {
+ event.preventDefault();
+ if (!navigator.share) {
+ console.log("navigator.share does not exist");
+ return;
+ }
+
+ canvas.toBlob(async (blob) => {
+ if (!blob) return;
+ const file = new File([blob], 'imagine.png', {type: 'image/png'});
+ try {
+ await navigator.share({files: [file]});
+ } catch (error) {
+ console.log('Error sharing:', error);
+ }
+ }, 'image/png');
}
function settings_apply(event) {