且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Imagick中读取SVG字符串?

更新时间:2023-02-17 09:07:49

您必须在$ 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;