Skip to content

Commit

Permalink
chore(export): scale exported images
Browse files Browse the repository at this point in the history
This restores the fix for #486 that somehow has been forgotten.
  • Loading branch information
nikku committed Feb 15, 2019
1 parent 9b519ec commit 7dbecc1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion client/src/app/util/generateImage.js
Expand Up @@ -6,6 +6,7 @@ const ENCODINGS = [
'image/jpeg'
];

const SCALE = 3;

export default function generateImage(type, svg) {
const encoding = 'image/' + type;
Expand All @@ -19,6 +20,11 @@ export default function generateImage(type, svg) {

canvas = document.createElement('canvas');


svg = svg.replace(/width="([^"]+)" height="([^"]+)"/, function(_, widthStr, heightStr) {
return `width="${parseInt(widthStr, 10) * SCALE}" height="${parseInt(heightStr, 10) * SCALE}"`;
});

canvg(canvas, svg);

// make the background white for every format
Expand All @@ -31,4 +37,4 @@ export default function generateImage(type, svg) {
context.fillRect(0, 0, canvas.width, canvas.height);

return canvas.toDataURL(encoding);
}
}

0 comments on commit 7dbecc1

Please sign in to comment.