From 9e44a41762dafccfd03ab4ecc884e8457cebab88 Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Sun, 4 Feb 2018 21:00:42 +0100 Subject: [PATCH 1/4] added possibility of saving as an svg file --- pages/editor.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pages/editor.js b/pages/editor.js index 04f4c10..547ae41 100644 --- a/pages/editor.js +++ b/pages/editor.js @@ -105,7 +105,7 @@ class Editor extends React.Component { saveState(localStorage, s) } - getCarbonImage() { + getCarbonImage(format) { const node = document.getElementById('export-container') const config = { @@ -118,6 +118,9 @@ class Editor extends React.Component { height: node.offsetHeight * 2 } + if (format === 'svg') { + return domtoimage.toSvg(node, config) + } return domtoimage.toPng(node, config) } @@ -129,10 +132,10 @@ class Editor extends React.Component { this.setState({ aspectRatio }) } - save() { - this.getCarbonImage().then(dataUrl => { + save(format) { + this.getCarbonImage(format).then(dataUrl => { const link = document.createElement('a') - link.download = 'carbon.png' + link.download = 'carbon.' + format link.href = dataUrl document.body.appendChild(link) link.click() @@ -142,7 +145,7 @@ class Editor extends React.Component { upload() { this.setState({ uploading: true }) - this.getCarbonImage() + this.getCarbonImage('png') .then(api.tweet) .then(() => this.setState({ uploading: false })) .catch(err => { @@ -187,7 +190,13 @@ class Editor extends React.Component { color="#57b5f9" style={{ marginRight: '8px' }} /> -