我正在使用SVG图像自定义后我将使用Image()函数将SVG转换为PNG,Chrome浏览器工作正常,但safari和firefox无法正常工作,我的代码如下,
<pre>
$('#next').click( function(){
var image = new Image();
var xml = '<?php echo str_replace(PHP_EOL,'',$_SESSION['tshirt']); ?>';
image.src = 'data:image/svg+xml,' + escape(xml);
document.getElementById('output').appendChild(image);
image.onload = function() {
image.onload = function() {};
var canvas = document.createElement('canvas');
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext('2d');
context.drawImage(image, 0, 0);
image.src = canvas.toDataURL();
}
});
</pre>
这是我的firefox窗口