我有一个包含svg元素标记的字符串.
<svg id="someId" width="300" height="300">
<polygon id="another_id" fill="green" stroke="black" stroke-width="5" points="200,100 131,5 19,41 19,159 131,195 "></polygon>
</svg>
Run Code Online (Sandbox Code Playgroud)
如何在Imagick中读取此字符串并显示它.
$svg = '<svg id="someId" width="300" height="300"><polygon id="another_id" fill="green" stroke="black" stroke-width="5" points="200,100 131,5 19,41 19,159 131,195 "></polygon>
</svg>';
$image = new Imagick();
// This is not working.
$image->readImageBlob($svg);
$image->setImageFormat("png");
header("Content-Type: image/png");
echo $image;
Run Code Online (Sandbox Code Playgroud)
如何读取这个svg字符串,以便我可以继续做其他的事情.谢谢
你必须<?xml version="1.0"?>在$ svg变量的开头添加.
这段代码适合我:
$svg = '<?xml version="1.0"?><svg id="someId" width="300" height="300"><polygon id="another_id" fill="green" stroke="black" stroke-width="5" points="200,100 131,5 19,41 19,159 131,195 "></polygon></svg>';
$image = new Imagick();
$image->readImageBlob($svg);
$image->setImageFormat("png");
header("Content-Type: image/png");
echo $image;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2912 次 |
| 最近记录: |