我遇到的问题几乎与此类似: ImagickException with message Postscript delegate failed on MAMP 3.0.5
我想阅读一个SVG文件(5套维恩图),我用php创建,我想把它写到png / jpeg或任何文件......没什么用。它打破了第3行:
$im = new Imagick();
$svg = $venn_diagram;
$im->readImageBlob($svg);
$im->setImageFormat("jpeg");
$im->adaptiveResizeImage(720, 445);
$im->writeImage($folder . 'output_venn_diagram.png');
$im->clear();
$im->destroy();
有了这个:
Fatal error: Uncaught exception 'ImagickException' with message 'no decode delegate for this image format `' @ error/blob.c/BlobToImage/359' in /myphp.php:500 Stack trace: #0 /myphp.php(500): Imagick->readimageblob('<svg version='1...') #1 {main} thrown in /myphp.php on line 500
它也打破了这个非常简化的SVG:
<svg version='1.0' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='746' height='742' viewBox='-362 -388 746 742' encoding='UTF-8' standalone='no'>
<defs>
<ellipse id='ellipse' cx='36' cy='-56' rx='160' ry='320' />
<g id='ellipses'>
<use xlink:href='#ellipse' fill='#0000ff' />
<use xlink:href='#ellipse' fill='#0099ff' transform='rotate(72)' />
</g>
</defs>
</svg>
我真的不知道该怎么做:
有人知道该怎么做吗?
感谢您的帮助!
答案 0 :(得分:3)
您的SVG无效xml,因此无效SVG
将其添加到SVG的开头:
<?xml version="1.0"?>
它应该有效。适合我的完整代码是:
$svg = <<< END
<?xml version="1.0"?>
<svg version='1.0' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' width='746' height='742' viewBox='-362 -388 746 742' encoding='UTF-8' standalone='no'>
<defs>
<ellipse id='ellipse' cx='36' cy='-56' rx='160' ry='320' />
<g id='ellipses'>
<use xlink:href='#ellipse' fill='#0000ff' />
<use xlink:href='#ellipse' fill='#0099ff' transform='rotate(72)' />
</g>
</defs>
</svg>
END;
$image = new \Imagick();
$image->readImageBlob($svg);
$image->setImageFormat("jpg");
header("Content-Type: image/jpg");
echo $image;
制作此图片: