【问题标题】:PHP SVG read on OSX Mavericks (MAMP 3) using Imagick使用 Imagick 在 OSX Mavericks (MAMP 3) 上读取 PHP SVG
【发布时间】:2014-06-24 13:03:13
【问题描述】:

我遇到了几乎和这里一样的问题: ImagickException with message Postscript delegate failed on MAMP 3.0.5

我想读取一个我用 php 创建的 SVG 文件(5 组维恩图),我想把它写到 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>

我真的不知道该怎么办:

  • MAMP / php 正在运行。
  • 我的文件开头有 SVG 规范,我检查了。
  • 我多次安装、卸载、重新安装(使用 brew)imagick。
  • 我也重新启动了 MAMP。

有人知道该怎么做吗?

感谢您的帮助!

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

【问题讨论】:

    标签: php macos svg mamp imagick


    【解决方案1】:

    您的 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;
    

    生成此图像:

    【讨论】:

    • 也试过了。可悲的是,这些都不起作用......
    • 感谢它的工作!美好的。上次发生了一些事情。您的代码有效!
    猜你喜欢
    • 2013-12-29
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-25
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多