From 9bab9a62297e9e425497ff18596a50e2b060a710 Mon Sep 17 00:00:00 2001
From: tonka3000
Date: Mon, 15 Jun 2020 17:56:33 +0200
Subject: [PATCH] add user configurable png size
---
src/components/Links.svelte | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/components/Links.svelte b/src/components/Links.svelte
index 63351bbd..aa6604bb 100644
--- a/src/components/Links.svelte
+++ b/src/components/Links.svelte
@@ -16,13 +16,22 @@ export const onDownloadPNG = event => {
const box = svg.getBoundingClientRect();
canvas.width = box.width;
canvas.height = box.height;
+ if(imagemodeselected === "width") {
+ const ratio = box.height/box.width;
+ canvas.width = userimagewidth;
+ canvas.height = userimagewidth * ratio;
+ } else if(imagemodeselected === "height") {
+ const ratio = box.width/box.height;
+ canvas.width = userimageheight * ratio;
+ canvas.height = userimageheight;
+ }
const context = canvas.getContext('2d');
context.fillStyle = "white";
context.fillRect(0, 0, canvas.width, canvas.height);
var image = new Image();
image.onload = function () {
- context.drawImage(image, 0, 0);
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
var a = document.createElement('a')
a.download = `mermaid-diagram-${moment().format('YYYYMMDDHHmmss')}.png`;
@@ -59,6 +68,9 @@ let b64Code;
let iUrl;
let svgUrl;
let mdCode;
+let imagemodeselected = "auto";
+let userimagewidth = 1920;
+let userimageheight = 1080;
const unsubscribe = codeStore.subscribe(state => {
b64Code = Base64.encodeURI(JSON.stringify(state));
@@ -100,3 +112,14 @@ label[for="markdown"] {
+
+
+
+
+
+
+
+
+
+
+