Skip to content

Instantly share code, notes, and snippets.

@compulim
Created August 26, 2019 01:46
Show Gist options
  • Save compulim/cca3a5f69ed302c6bb513aa1cf8a7de0 to your computer and use it in GitHub Desktop.
Save compulim/cca3a5f69ed302c6bb513aa1cf8a7de0 to your computer and use it in GitHub Desktop.
Render SVG to download as PNG
<!DOCTYPE html>
<!-- Very unpolished, just for the very short purpose -->
<html lang="en-US">
<head>
<title>Render logo</title>
<script type="text/javascript">
(async function () {
'use strict';
const SIZE = 192;
function loadImage(src) {
return new Promise((resolve, reject) => {
const img = document.createElement('img');
img.addEventListener('error', ({ error }) => reject(error));
img.addEventListener('load', () => resolve(img));
img.setAttribute('src', src);
});
}
async function main() {
const image = await loadImage('./azure-bot-services.svg');
const canvas = document.createElement('canvas');
canvas.setAttribute('height', SIZE + '');
canvas.setAttribute('width', SIZE + '');
const context = canvas.getContext('2d');
context.drawImage(image, 0, 0, SIZE, SIZE);
document.body.appendChild(canvas);
}
main();
}()).catch(console.error.bind(console));
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment