I want to load an SVG image, do some manipulation of its .contentDocument , and then draw it on the canvas.
A good example for drawing SVG on canvas can be found here: http://www.phrogz.net/tmp/canvas_from_svg.html
But in this example, svg was created as a new Image('url.svg') object new Image('url.svg') . When you create an SVG in this way, unfortunately, it has no manipulation of the contentDocument. It seems to be only one when you create it as a <object> element.
But when I create the SVG as an object, get the SVG DOM node and pass it to context.drawImage(svgNode, x, y) , it throws the error "Value could not be converted to any of: HTMLImageElement, HTMLCanvasElement, HTMLVideoElement." (in Firefox).
It seems I either have to find a way to convert the SVG object to an HTMLImageElement element, or a way to get the SVG content document that was loaded as an image. Does anyone know how to do this? Or is there a third way to do this that I am missing?
source share