下面的javascript代码将SVG字符串转换成图像blob,然后用于在浏览器中显示:
var data = '<svg xmlns="http://www.w3.org/2000/svg" width="390" height="65">' +
'<rect x="0" y="0" width="100%" height="100%" fill="#7890A7" stroke-width="20" stroke="#ffffff" ></rect>' +
'<foreignObject x="15" y="10" width="100%" height="100%">' +
'<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:40px">' +
' <em>I</em> am' +
'<span style="color:white; text-shadow:0 0 20px #000000;">' +
' HTML in SVG!</span>' +
'</div>' +
'</foreignObject>' +
'</svg>';
var DOMURL = window.URL || window.webkitURL || window;
var img = new Image();
var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
var url = DOMURL.createObjectURL(svg);
麻烦的是,我希望能够做同样的事情,但在PHP。我想用imagecreatefromstring
函数。这是正确的做法吗?
From PHP manual for imagecreatefromstring
(http://php.net/manual/en/function.imagecreatefromstring.php)
imagecreatefromstring()返回一个图像标识符从给定图像中获得的图像。这些类型将自动检测您构建的PHP是否支持以下格式:JPEG、PNG、GIF、WBMP和阻止GD2 .
SVG不会出现在链接页面的任何地方