【问题标题】:How to read SVG string in Imagick?如何在 Imagick 中读取 SVG 字符串?
【发布时间】:2014-09-14 05:20:59
【问题描述】:

我有一个包含 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>

如何在 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;

我怎样才能阅读这个 svg 字符串,以便我可以继续做其他事情。谢谢

【问题讨论】:

标签: php svg imagick


【解决方案1】:

您必须在 $svg 变量的开头添加&lt;?xml version="1.0"?&gt;

此代码适用于我:

$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;

【讨论】:

    猜你喜欢
    • 2022-07-24
    • 2015-07-11
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多