简体   繁体   English

使用Imagick在OSX Mavericks(MAMP 3)上读取PHP SVG

[英]PHP SVG read on OSX Mavericks (MAMP 3) using Imagick

I have nearly the same problem like here: ImagickException with message Postscript delegate failed on MAMP 3.0.5 我有几乎相同的问题,如下所示: ImagickException与消息Postscript委托在MAMP 3.0.5上失败

I would like to read an SVG file (5 set Venn Diagram), which I created with php and I would like to write it out to a png/jpeg or whatever file... nothing work. 我想读取一个SVG文件(5组维恩图),该文件是用php创建的,我想将其写到png / jpeg或任何文件中……什么都不起作用。 It breaks on the 3rd line: 它在第三行中断:

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

With this: 有了这个:

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

It breaks also with this very simplified SVG also: 这个非常简化的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>

I don't really know what to do: 我真的不知道该怎么办:

  • MAMP / php running. MAMP / PHP的运行。
  • I have SVG specification in the beginning of my file, I checked. 我检查了文件开头是否有SVG规范。
  • I installed, uninstalled, reinstalled (with brew) imagick several times. 我安装,卸载,重新安装了imagick(与brew)多次。
  • I restarted MAMP also. 我也重新启动了MAMP。

Do somebody know what to do? 有人知道该怎么办吗?

Thanks for help! 感谢帮助!

  • OS X Mavericks 10.9.3 OS X小牛10.9.3
  • MAMP 3.05 MAMP 3.05
  • php 5.5.10 PHP 5.5.10
  • imagemagick 6.8.9-1 imagemagick 6.8.9-1

Your SVG isn't valid xml and so isn't valid SVG 您的SVG无效xml,因此无效SVG

Add this to the start of the SVG: 将其添加到SVG的开头:

<?xml version="1.0"?>

And it should work. 它应该工作。 The complete code that works for me is: 适用于我的完整代码是:

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

Produces this image: 产生此图像:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM