如何在Imagick中读取SVG字符串? [英] How to read SVG string in Imagick?
本文介绍了如何在Imagick中读取SVG字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含svg元素标记的字符串.
I have a string containing markup for an svg element.
<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>
如何在Imagick中读取此字符串并显示它.
How can I read this string in Imagick and display it.
$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;
如何读取此svg字符串,以便继续进行其他工作.谢谢
How can I read this svg string so that I can proceed with doing other stuffs. Thanks
推荐答案
您必须在$ svg变量的开头添加<?xml version="1.0"?>
.
You have to add <?xml version="1.0"?>
in the begining of $svg variable.
此代码对我有用:
$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;
这篇关于如何在Imagick中读取SVG字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文