From f604780056f6164ac229f5405c885bad9703747a Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Wed, 9 Jan 2019 14:48:03 +1200 Subject: [PATCH] ** --- desktop/sources/scripts/renderer.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/desktop/sources/scripts/renderer.js b/desktop/sources/scripts/renderer.js index 1819d4e..94e4088 100644 --- a/desktop/sources/scripts/renderer.js +++ b/desktop/sources/scripts/renderer.js @@ -43,34 +43,39 @@ DOTGRID.Renderer = function () { } this.svg64 = function () { - this.update() let xml = new XMLSerializer().serializeToString(this.el) let svg64 = btoa(xml) let b64Start = 'data:image/svg+xml;base64,' return b64Start + svg64 } + // Exporters + this.toPNG = function (size = DOTGRID.tool.settings.size, callback) { + this.update() + let image64 = this.svg64() let img = new Image() let canvas = document.createElement('canvas') canvas.width = (size.width) * 2 canvas.height = (size.height) * 2 - let ctx = canvas.getContext('2d') img.onload = function () { - ctx.drawImage(img, 0, 0, (size.width) * 2, (size.height) * 2) - let data = canvas.toDataURL('image/png') - callback(data, 'export.png') + canvas.getContext('2d').drawImage(img, 0, 0, (size.width) * 2, (size.height) * 2) + callback(canvas.toDataURL('image/png'), 'export.png') } img.src = image64 } this.toSVG = function (callback) { + this.update() + const image64 = this.svg64() callback(image64, 'export.svg') } this.toGRID = function (callback) { + this.update() + const text = DOTGRID.tool.export() const file = new Blob([text], { type: 'text/plain' }) callback(URL.createObjectURL(file), 'export.grid')