From fdabd61b142a6ce36fec170fc6eaa6a7b127cc99 Mon Sep 17 00:00:00 2001 From: HeptaDecane Date: Fri, 30 Jul 2021 15:21:40 +0530 Subject: [PATCH] added save as png --- app/index.html | 1 + app/models/canvas.js | 8 ++++++++ app/screens/editor.js | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/app/index.html b/app/index.html index 094564c..d7872d6 100644 --- a/app/index.html +++ b/app/index.html @@ -242,6 +242,7 @@
Convert to commands..
+
Save as PNG..
Help
diff --git a/app/models/canvas.js b/app/models/canvas.js index 6277a0c..6594b19 100644 --- a/app/models/canvas.js +++ b/app/models/canvas.js @@ -1702,6 +1702,14 @@ function MineartCanvas() { this.render() } + this.getDataUrl = function() { + if (store.imageWidth > 256 || store.imageHeight > 256) { + if (!confirm("Images with width/length more than 256 blocks may cause performance issues.\nContinue?")) + return null + } + return canvasTemp.toDataURL() + } + this.render = () => { this._renderMainCanvas() this._renderOverlayCanvas() diff --git a/app/screens/editor.js b/app/screens/editor.js index 44c5472..0bff8e5 100644 --- a/app/screens/editor.js +++ b/app/screens/editor.js @@ -498,6 +498,14 @@ const store = { this.$helpControls.onclick = () => { store.parent.modals.openModal('controls') } + this.$btnSavePng.onclick = function() { + var n = new Image + , e = store.parent.mineartCanvas.getDataUrl(); + if (null !== e) { + n.src = e; + window.open(e).document.write(n.outerHTML) + } + } } }