Convert SVG to PNG

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
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Convert SVG to PNG

Post by novito »

I am trying to find a way to convert any SVG image to a PNG.

Here is what I have tried so far:

convert -background none logo_svg.svg b.png

In some cases, the PNG image is written (even though there are missing colors), even though the image is not the same one. Example:

Original Image: http://jet-computing.com/wp-content/upl ... x.svg_.png
Result: http://imgur.com/pywEaZs

And in other cases, such as this case:

Original: http://demandware.edgesuite.net/aaci_pr ... s/logo.svg

When trying to run that command, I get: 'convert: non-conforming drawing primitive definition `path' @ error/draw.c/DrawImage/3179.'

Any thoughts?
For the records, here are the SVG libs that are shown when doing convert -list format:

SVG SVG rw+ Scalable Vector Graphics (XML 2.9.1)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (XML 2.9.1)
Last edited by novito on 2014-07-30T10:51:08-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert SVG to PNG

Post by fmw42 »

What version of IM and platform are you using. And more importantly what delegate is being used for SVG -- IM internal MSVG (XML), RSVG or Inkscape.

convert -list format

see what delegate is listed for SVG

For example on my system

SVG SVG rw+ Scalable Vector Graphics (RSVG 2.40.2)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (RSVG 2.40.2)

You should use Inkscape or RSVG with the most current versions.

If there is still an issue, then your svg file may be corrupt or have non-standard syntax.

Some bugs in this regard have been fixed in current versions of IM.

From the changelog (some of the recent changes):

2014-07-19 6.8.9-6 Dirk Lemstra <dirk@snakeware...>
Fixed fill-rule in SVG clip path (reference viewtopic.php?f=2&t=25882).


2014-06-07 6.8.9-3 Dirk Lemstra <dirk@snakeware...>
Fixed creation of SVG from 8bim clip path. (reference viewtopic.php?f=1&t=25594).


2013-12-30 6.8.8-2 Cristy <quetzlzacatenango@image...>
Generate a proper SVG clipping path (reference viewtopic.php?f=3&t=24752).


2012-12-21 6.8.8-0 Dirk Lemstra <dirk@snakeware...>
Made librsvg the default svg library for the windows distribution.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert SVG to PNG

Post by snibgo »

Code: Select all

convert -background none logo_svg.svg b.png
This works fine with IM 6.8.9-5 with Inkscape as the renderer.
snibgo's IM pages: im.snibgo.com
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Re: Convert SVG to PNG

Post by novito »

Hi guys,

I am using Version: ImageMagick 6.8.8-3 Q16 x86_64 2014-03-03 http://www.imagemagick.org (for MAC)

And the

Code: Select all

convert -list format
shows me this (regarding SVG):

SVG SVG rw+ Scalable Vector Graphics (XML 2.9.1)
SVGZ SVG rw+ Compressed Scalable Vector Graphics (XML 2.9.1)

I don't see any RSVG there, so I guess your suggestions would be to install RSVG and reinstall ImageMagick?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert SVG to PNG

Post by snibgo »

MSVG is very limited. I guess it just can't cope with paths.

As you goal is to convert any SVG, I suggest Inkscape is the most suitable delegate.
snibgo's IM pages: im.snibgo.com
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Re: Convert SVG to PNG

Post by novito »

How can I tell ImageMagick to use Inkscape as a delegate for SVG? I am on my way to reinstall ImageMagick with MacPorts: https://trac.macports.org/browser/trunk ... k/Portfile
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert SVG to PNG

Post by snibgo »

On Windows, just install Inkscape and put its directory on the system path. I don't know about other platforms.
snibgo's IM pages: im.snibgo.com
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

Re: Convert SVG to PNG

Post by novito »

You guys rock. For the records, this is what I did:

Code: Select all

port uninstall imagemagick
brew install librsvg
port install imagemagic +rsvg
Voila, problem solved. Thanks guys.
Post Reply