3

Here is a fiddle of an example that takes an svg and turns it into a canvas: http://jsfiddle.net/Na6X5/944/

var can = document.getElementById('canvas1'); var ctx = can.getContext('2d'); var svg = document.getElementById('mySVG'); var img = new Image(); img.onload = function() { console.log(img.width, img.height) document.getElementById('canvas1').width = 300 document.getElementById('canvas1').height = 200 ctx.drawImage(img, 0, 0, 300, 200); } img.src = "data:image/svg+xml," + encodeURIComponent(svg.outerHTML) 

This works fine on Chrome(51.0). But produces an empty canvas on Firefox(47.0.1) with no errors.

This example works on Firefox http://codepen.io/keithwyland/pen/umova but changing the src of the image to an inline svg produces the problem listed above http://codepen.io/Ewhite613/pen/YWZoGy

0

1 Answer 1

8

It used to be the case that SVG image data had to have width and height attributes that are were not percentages but this was fixed some time ago.

Sign up to request clarification or add additional context in comments.

1 Comment

The canvas html element must also be styled as display:block

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.