Converting SVG to another format fail due to delegate not being found


Converting SVG to another format fail due to delegate not being found



I have PHP code running on Debian stretch with ImageMagick. It tries to convert SVG to another format. Here is how it starts


$im = new Imagick();
$im->readImageBlob($svg);



The variable $svg contains valid SVG code in a string. If I copy this string to a text file with a .svg extension then it opens just fine. But readImageBlob throws an exception saying no delegate for this image format.


$svg


.svg


readImageBlob


no delegate for this image format



I have seen similar questions solved by installing more packages to the system. But I've already installed libxml2-dev, librsvg2-bin, libmagickcore-6.q16-3-extra and libfreetype6-dev.


libxml2-dev


librsvg2-bin


libmagickcore-6.q16-3-extra


libfreetype6-dev



I have no idea what else I am missing.





What's the first line of the SVG file? There may be some comments, whitespace, and/or XML headers that Imagick::readImageBlob doesn't understand.
– emcconville
Jun 28 at 13:02


Imagick::readImageBlob





Also try setting a "dummy" filename to the method. $im->readImageBlob($svg, 'filename.svg');
– emcconville
Jun 28 at 13:03


$im->readImageBlob($svg, 'filename.svg');





Imagick::readImageBlob — Reads image from a binary string. You are sending ascii data, not binary. So save the string to a text file and use readImage().
– fmw42
Jul 2 at 18:36


binary string




2 Answers
2



What do you get from running the following command from PHP exec()



convert -list format


convert -list format



The line SVG should say RSVG or MSVG/XML. Does it show that? if you need RSVG, you will have to install that delegate and then reinstall Imagemagick so that Imagemagick can find it. Imagemagick is used by Imagick. They are not the same. The RSVG delegate can be found by a Google Search or from linuxfromscratch.org/blfs/view/svn/general/librsvg.html. Your svg file seems to render properly for me in Imagemagick using RSVG, but I am not sure what it should look like. It is just a graph set of horizontal lines.



I do not know much about using readImageBlob(). Just use readImage(), where you supply the path to a saved svg image file. That should work. Try that and see what you get.



Here is what I get using RSVG 2.42.2 in Imagemagick 6.9.10.3 Q16 Mac OSX were I have saved your text in a file called test.svg.


convert test.svg test.png



enter image description here



If I force the use of the Imagemagick MSVG/XML, it does not look as good.


convert MSVG:test.svg test2.png



enter image description here





Indeed it seems it uses MSVG rather than RSVG. RSVG does it correctly. You can see here three columns but they are all zero so they show as tiny lines. MSVG which was used for me places word "Gigabytes" at a wrong position. Imagemagick was installed from a debian package. librsvg2-bin was also installed as another package afterwards. But it still uses MSVG
– Gherman
Jul 3 at 9:02





Imagemagick has to know or be recompiled to find RSVG. As your host if they can install Inkscape, if your Imagemagick version is 6.7.9-0 or was patched after 2012-08-14. Imagemagick will then find Inkscape and use that in place of RSVG or MSVG
– fmw42
Jul 3 at 17:15



I had to prepend the $svg with <?xml version="1.0" ?> and it worked. It least it does read in the SVG and attempts to create png/jpeg. One piece of text gets misplaced during convertion though. So the task in general is still failed. But this is another issue. I think the question is answered.


$svg


<?xml version="1.0" ?>





Render quality depends upon which SVG renderer Imagemagick is using. You can see that with convert -list format. Imagemagick can use Inkscape, RSVG delegate or its own internal MSVG/XML renderer in order of best to worst quality. You would be best to install Inkscape and Imagemagick will use it if it finds it. Next, install the RSVG delegate to imagemagick and recompile Imagemagick if needed. If you post your SVG file, I can test it with my Imagemagick using RSVG.
– fmw42
Jun 28 at 16:20


convert -list format





@fmw42 I could not find such information about SVG delegates. Where can I get more details on this? I cirtainly didn't have Inkscape installed. Here is my image pastebin.com/fRSeHR7N It's actually a plot generated by Google Charts
– Gherman
Jul 2 at 12:31






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages