Last active
August 19, 2020 12:43
-
-
Save mubaidr/7eb1f655164b1182c603af8154f38289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSvgAsImage(svgElem, viewBox) { | |
// TODO: add x,y to w,h | |
var canvas = document.createElement('canvas') | |
canvas.width = viewBox[2] | |
canvas.height = viewBox[3] | |
var ctx = canvas.getContext('2d') | |
ctx.fillStyle = '#fff' | |
ctx.fillRect(0, 0, canvas.width, canvas.height) | |
var options = { | |
// fetch: | |
ignoreMouse: true, | |
ignoreAnimation: true, | |
// ignoreDimensions: true, | |
ignoreClear: true, | |
scaleWidth: 500, | |
// scaleHeight: 400, | |
} | |
Canvg.fromString(ctx, svgElem.outerHTML, options).render() | |
return canvas.toDataURL('image/jpeg', 1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment