Rasterize SVG with right density?

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
Mazin
Posts: 10
Joined: 2008-11-24T13:30:50-07:00

Rasterize SVG with right density?

Post by Mazin »

I would like to convert an SVG into a PNG and enlarge it to a specific size in the process (e.g. to 300px on the longest side). However, simply doing

Code: Select all

convert -resize 300x300 in.svg out.png
gives poor results because the image becomes pixelated. Can I get IM to render it with the correct density for a certain size (rather than calculate the density myself)?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Rasterize SVG with right density?

Post by fmw42 »

try

convert -density 400 in.svg -resize 300x300 out.png

Make the density larger if you want better quality in the 300x300 pixels. The 400 is just a guess at what might make the svg file bigger than 300x300 pixels. Try various values for a trade between quality and speed. P.S. I am not an expert on SVG files, but this is generally what is done for any vector format.
Mazin
Posts: 10
Joined: 2008-11-24T13:30:50-07:00

Re: Rasterize SVG with right density?

Post by Mazin »

fmw42 wrote:convert -density 400 in.svg -resize 300x300 out.png
I thought about doing that, but it seems like a waste of CPU and memory. It runs the risk of undersampling (e.g. rendering a 16x16px SVG to a 300x300 PNG) or eating up too much memory (e.g. rendering a 10x10m SVG to a 300x300 PNG). The first problem is undesirable, but the second is dangerous.
Post Reply