Page 1 of 1

Rasterize SVG with right density?

Posted: 2011-04-12T17:07:20-07:00
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)?

Re: Rasterize SVG with right density?

Posted: 2011-04-12T17:26:26-07:00
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.

Re: Rasterize SVG with right density?

Posted: 2011-04-12T17:35:59-07:00
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.