Google
 
Web Ben's Questions and Answers

Wednesday, July 27, 2005

Convert SVG to PNG Without Antialiasing

Someone on Slashdot asked if there was any way to convert SVG vector graphics files to PNG raster graphics files without having fixed width lines blurred through the use of antialiasing.

The ImageMagick convert untility provides many useful image conversion tools and will convert from SVG to PNG. The way that convert deals with antialiasing is a little confusing however. The person who asked the question stated that they had already turned off antialiasing by calling:

$ convert -antialias a.svg a.png

Unfortunately "-antialias" turns antialiasing on not off. To turn antialiasing off you need to use "+antialias" e.g.:

$ convert +antialias a.svg a.png

Have you ever had any problems converting SVG files to PNG?

I hope that that clarifies a point of confusion, if you have any comments please let me know and if you have any other questions which you'd like me to answer for free please send them to Ben Dash at ben.dash@gmail.com

8 Comments:

Anonymous csirac said...

Hi there,

I'm that slashdot person who posted the question. Thanks for the tip! I can't believe I didn't read the man page more closely...

Well, antialiasing is now off and I can do sensible difference bitmaps more reliably now.

Things are only 99.9% good though ;) You said "have you ever had problems converting .svg to .png" - so here it is. I still can't convert directly to .png and have them open with mspaint.exe on Windows XP SP1a (corporate image). Silly error I know; they open fine in iexplore.exe and irfanview and the gimp.

I have to use .bmp as an intermediate format. For some reason, going straight from .svg to .png in the one command creates a strange .png file that doesn't open in mspaint.exe at all.

I had this problem with the standard ImageMagick binaries that come with cygwin (version 6.0.something, IIRC) so I downloaded the latest source and compiled with gcc 3.4.4 but still had the same problem. Also tried compile & run on MacOS 10.3.

As I was just doing "mspaint file.png" from the command line (I do everything from a cygwin bash prompt as I'm forced to use Windows XP at work), I had just assumed the .png was corrupt. But it seems more likely now I've merely found a way of invoking a bug in mspaint.exe.

Version: ImageMagick 6.2.3 07/19/05 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2005 ImageMagick Studio LLC

I'm not worried about this bug, just thought it was odd. Obviously Microsoft's own apps use different PNG loader libs to each other. No matter.

Cheers

8:15 PM  
Blogger Ben Dash said...

Thanks for letting me know about mspaint's problem with png files. To be honest I didn't realise that mspaint had any png support. Luckilly I have both XP and Gentoo at work so rarely ever have to resort to using mspaint.

You can convert directly to a bmp or a jpg instead of a png, that may solve your problem. I had trouble with converting to a bmp just now but a jpg worked fine.

2:50 AM  
Blogger Ben Dash said...

Oh I see what you're saying, sorry, please ignore my comment, you're already using bmp as an intermediate stage. For some reason that doesn't work for me. I have to use jpg instead.

10:41 AM  
Anonymous Anonymous said...

Who on earth thought that it would be a good idea to turn on antialiasing with a "-" and turn it off with a "+"???

3:43 PM  
Anonymous NEG said...

Many great photo process software can convert SVG to PNG, like the GIMP, it can do it perfect I just found.

2:58 AM  
Blogger nitrofurano said...

do you know how can we convert an svg to png with opacity?

7:36 AM  
Blogger Ben Dash said...

Did you try this?

---
convert -density 100 -background None [filename].svg -compress none -depth 16 [filename].png
---

10:15 PM  
Blogger buyi wen said...

you can try this free online image converter to convert svg to png online.

9:34 AM  

Post a Comment

<< Home