Why do I get NoDecodeDelegateForThisImageFormat when rastering SVG to PNG with ImageMagick in PHP?

萝らか妹 提交于 2019-12-23 18:30:32

问题


I'm trying to convert svg image to png with the following code:

$image = new Imagick();
$image->readImageBlob($_POST['svgcode']);
$image->setImageFormat("png24");
$image->resizeImage(600, 600, imagick::FILTER_LANCZOS, 1);
header('Content-type: image/png');
echo $image;

But there is an error in the second line:

NoDecodeDelegateForThisImageFormat `' @ error/blob.c/BlobToImage/361

How can I fix this?


回答1:


First line of your svg must be <?xml version="1.0" encoding="UTF-8" standalone="no"?>

$svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.$svg;

Do it and you will be enjoying :-)




回答2:


This post helped me a lot http://www.elxsy.com/2009/07/installing-imagemagick-on-windows-and-using-with-php-imagick/

To be exact this piece:

This is the important part, I spent good half an hour trying to make it work.. grrrr.. You need to restart your PC to libraries take effect.

Never did this for installing php extensions.



来源:https://stackoverflow.com/questions/18661811/why-do-i-get-nodecodedelegateforthisimageformat-when-rastering-svg-to-png-with-i

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!