SVG files created with IM are not rendered in browsers

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
gialloporpora
Posts: 6
Joined: 2011-04-05T05:57:23-07:00
Authentication code: 8675308

SVG files created with IM are not rendered in browsers

Post by gialloporpora »

Hi all,
I have a question about conversion of PNG files to SVG with ImageMagick.

I'am using ImageMagick 6.7.3-8 q16 for Win32 to convert some PNG to SVG format:

I convert my PNG file with ImageMagick:

Code: Select all

convert input.png output.svg
convert input.png output.svgz (compressed version)
Now, if I try to open it them with Firefox (or another browser like Opera) it opens the SVG like an XML file with missing stylesheet:

Resulting SVG created with ImageMagick

Instead, if I use Inkscape to convert my PNG file it works:

SVG created with Inkscape

Why the image converted with ImageMagick is not displayed by browsers?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG files created with IM are not rendered in browsers

Post by anthony »

I can confirm that this appears to be the case. Though I am not certain why.

Mind you, converting a raster image directly to SVG using IM is NOT recommended as it basically generates a large file of small dots, unless you enable the use of the rasterization library "autotrace" when compiling Imagemagick.

See IM Examples... SVG Output Handling
http://www.imagemagick.org/Usage/draw/#svg_output
And Edging using a Raster to Vector Converter
http://www.imagemagick.org/Usage/transform/#edge_vector

The Mime type of both image examples provided are both image/svg+xml so that does not appear to be the problem with the browsers internal SVG handling.

however even rsvg-view is not handling the SVG file generated, so something is VERY wrong!

Definate bug.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: SVG files created with IM are not rendered in browsers

Post by magick »

rsvg-view, version 2.34.2, worked for us for both the ff64im.svg and for this command:
  • convert logo: output.svg
We suspect the large number of circles is taxing some of the SVG rendering engines.
User avatar
gialloporpora
Posts: 6
Joined: 2011-04-05T05:57:23-07:00
Authentication code: 8675308

Re: SVG files created with IM are not rendered in browsers

Post by gialloporpora »

Thanks Anthony and Magick for your reply :-)
In fact, I have never used SVG before, but I am curious to learn more about this argument.
I have seen that the Inkscape image is not a real SVG image, it is only a PNG (in data link format) embedded in the resulting XML file.

Thanks for your answer to my question :-)
Sandro
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG files created with IM are not rendered in browsers

Post by anthony »

Can you provide use an example of that PNG embedded in a SVG?

This would be a much better solution for general conversion of images to SVG.

The other method that IM can provide is by compiling IM with a autotrace delegate library. In that case IM will use that library to generate vector forms of SVG, especially for black and white images.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply