Imagick SVG到JPG错误没有解码委托


Imagick SVG to JPG error no decode delegate

我尝试了许多不同的解决方案,但无法使用Imagick::readImageBlob,任何帮助将不胜感激。

错误信息:

Caught exception: no decode delegate for this image format `' @ error/blob.c/BlobToImage/364
代码:

$svg = file_get_contents($this->svg);
$image = new Imagick();
$image->readImageBlob($svg);
//...
SVG:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
    <svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" version="1.1" width="928" height="933" id="parent">
        <image width="928" height="933" xlink:href="image.jpg" ></image>
        <path id="path1" fill="none" d="M100,656.5c-105.1-200.5-28.1-448,172-553s447.5-27.5,552.6,173s28.1,448-172,553 S205.1,856.9,100,656.5z"/>
        <text text-anchor="middle">
            <textPath xlink:href="#path1" startOffset="33.3333%">
                <tspan>top</tspan>
            </textPath>
        </text>
        <path id="path2" fill="none" d="M121.8,264.8C10.2,453.3,72.2,696.3,260.3,807.7s431,48.9,542.6-139.5 s49.5-431.5-138.5-542.8S233.3,76.4,121.8,264.8z"/>
        <text text-anchor="middle">
        <textPath xlink:href="#path2" startOffset="33.3333%">
            <tspan>bund</tspan></textPath>
        </text>
    </svg>

对于我来说这些深度是缺失的(ubuntu 16.04):

sudo apt-get install libgraphicsmagick1-dev libmagickcore-dev libmagickcore-6.q16-2 libmagickcore-6.q16-2-extra

期望输出:

identify -list format | grep SVG
     MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
      SVG  SVG       rw+   Scalable Vector Graphics (RSVG 2.40.13)
     SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (RSVG 2.40.13)

经过@Native Coder和@karser的尝试后,我的SVG仍然产生相同的无解码委托错误。在我将<?xml version="1.0" encoding="UTF-8" standalone="no"?>添加为SVG内容的开头行之后,它就工作了。也值得检查XML是否有效。

我可以通过安装inkscape来解决这个问题。

apt-get install inkscape

请看我的评论:https://stackoverflow.com/a/63175979/751202

使用Ubuntu 20.04,我运行下面的命令来安装libmagickcore-6包。

这个包增加了对SVG, WMF, OpenEXR, DjVu和Graphviz的支持。有几个不同的版本,例如,其中一个版本是为高动态范围(Q16HDRI)的16位通道深度编译的。

 sudo apt install libmagickcore-6*
使用上面的命令,似乎我安装了所有的不同版本。不确定这是否是最好的斜杠最有效的方式,但它确实解决了这个问题。

Docker image alpine, work for me:

RUN apk add --update imagemagick imagemagick-libs imagemagick-dev '
    && pecl install imagick '
    && docker-php-ext-enable imagick

对于将来读到这篇文章的人,我也有同样的问题。问题是我缺少libxml2和librsvg2-bin。

对于我来说,我尝试了上面所有的解决方案都没有结果,我终于安装了inkscape(这是由imagemagick使用的),它现在工作得很好!

sudo apt-get install inkscape