Hillboy
Hillboy

Reputation: 695

Canvas drawImage inline svg doesn't work on Firefox

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

Upvotes: 3

Views: 1729

Answers (1)

Robert Longson
Robert Longson

Reputation: 124014

The SVG image data must have width and height attributes that are not percentages.

Upvotes: 9

Related Questions