ImageMagick convert SVG to PNG not working with RSVG enabled
Asked Answered
S

3

10

I'm using ImageMagick's convert utility to convert SVG file to PNG image. At first, I used vanilla installation of IM on OSX (brew install imagemagick) to convert the SVG using:

$ convert file.svg file.png

This worked except that some of the image objects in that file were offset (actual links to images). I then read a related question that suggested ImageMagick to be compiled with rsvg support (homebrew does it with brew install imagemagick --use-rsvg).

Now, when I try to perform the conversion, no images are rendered. I tried using this SVG file, and the resulting PNG was blank. However, if any text exists on the SVG, it's rendered in the proper location. Any ideas how to proceed? thanks.

Searby answered 21/7, 2012 at 12:16 Comment(1)
Try Inkscape. If you install that on your system, Imagemagick will use it automatically over RSVG or MSVG.Tricotine
N
3

Oh, I now had a look at the SVG file you linked to.

It contains JavaScript. I do not think that the RSVGlib does support JavaScript inside SVGs. I know for sure that the internal SVG coder named MSVG does not.

Nieshanieto answered 21/7, 2012 at 18:2 Comment(1)
Thanks for your help. I also tried it on a file that contained only images and text.Searby
N
20

You should run this command to see a list of all 'delegates' your ImageMagick is trying to use:

 convert -list delegate

To discover which delegate command ImageMagick uses for SVG processing, run

 convert -list delegate | grep 'svg ='

You should see the binary + commandline parameters your convert tries to use. Im my case it is /opt/local/bin/rsvg-convert (but I'm not using Homebrew, I use MacPorts).

Now check if the binary is present at all on your system:

  • If yes, run it directly and debug from there.
  • If no, try to find where your Homebrew installation installed it, and change ImageMagick's configuration file for its delegates. It's called delegates.xml. MacPorts places it into /opt/local/etc/ImageMagick/delegates.xml -- I don't know where Homebrew stores it.

However, since your un-modified installation was already working, there must have been an SVG consuming delegate at work already then. Otherwise you would not have gotten any SVG processed at all.

This internal SVG rendering method of ImageMagick is called MSVG. This is far from being a feature-complete SVG interpreter/renderer.


Update:

To see what ImageMagick is doing for which format, run this command:

convert -list format

and for SVG run

convert -list format | grep SVG

Output on my system is:

 MSVG  SVG       rw+   ImageMagick's own SVG internal renderer
  SVG  SVG       rw+   Scalable Vector Graphics (RSVG 2.36.1)
 SVGZ  SVG       rw+   Compressed Scalable Vector Graphics (RSVG 2.36.1)

After you installed rsvg, the internal method to render SVGs will not have gone away. You can still force ImageMagick to use the internal renderer by adding MSVG: to the commandline like this:

convert  MSVG:file.svg  file.png

Just for completeness' sake...

Nieshanieto answered 21/7, 2012 at 17:41 Comment(3)
I also have /usr/local/bin/rsvg-convert, specifically: $ convert -list delegate | grep ` cdr => "uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"` ` svg => "rsvg-convert" -o "%o" "%i"`Searby
Has your /usr/local/bin/rsvg-convert the executable bit set? Does it work on the commandline with the command given, i.e.: /usr/local/bin/rsvg-convert -o out.png in.svg?Nieshanieto
Thanks again for following up on this. I have the exact same output as you do when running convert -list format | grep SVG, and when running convert MSVG:file.svg file.png I do get the output with the images, albeit they're offset somewhat (which was my original problem). rsvg-convert, which is sym-linked to /usr/local/Cellar/librsvg/2.36.1/bin/rsvg-convert, has 755 permissions.Searby
N
3

Oh, I now had a look at the SVG file you linked to.

It contains JavaScript. I do not think that the RSVGlib does support JavaScript inside SVGs. I know for sure that the internal SVG coder named MSVG does not.

Nieshanieto answered 21/7, 2012 at 18:2 Comment(1)
Thanks for your help. I also tried it on a file that contained only images and text.Searby
P
-2

I had a similar problem and was just told to install inkscape and it works,

ImageMagick converts svg graph into pdf with tilted x-axis labels, any ideas?

The delegate list did not change but the output did. On further fiddling with forced MSVG I could not get the problem to go away. So another delegate is probably the best solution.

Pterous answered 10/2, 2019 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.