title: How to convert SVG to PNG while keeping aspect ratio but changing extents?
body: <p>I'm trying to convert an SVG to a PNG.  The SVG is a non-square rectangle.  I want the aspect ratio of the image to stay the same, so the extents of the image need to be filled (transparent).</p>
  
  <p>I am on OS X Mavericks, 10.9.2.</p>
  
  <p>I've tried this with 3 tools, and each has issues:</p>
  
  <h1>With ImageMagick:</h1>
  
  <pre><code>convert -background none -resize 200x200 -gravity center -extent 200x200 rect.svg rect-imagemagick.png 
  </code></pre>
  
  <p>START --</p>
  
  <p><a href="https://i.stack.imgur.com/Zx3zP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Zx3zP.png" alt="enter image description here"></a></p>
  
  <p>END --</p>
  
  <p><strong>Image is square with correct aspect ratio, but is fuzzy.</strong>  I've seen other users report this issue with imagemagick converting SVGs to PNG.  I have upgraded imagemagick to use rsvg (via brew) as can be seen in the delegates of the version below.</p>
  
  <p>Version:</p>
  
  <pre><code># convert --version
  Version: ImageMagick 6.9.1-3 Q16 x86_64 2016-01-23 http://www.imagemagick.org
  Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
  License: http://www.imagemagick.org/script/license.php
  Features: DPC Modules
  Delegates (built-in): bzlib cairo fontconfig freetype jng jpeg ltdl lzma png rsvg tiff xml zlib
  </code></pre>
  
  <h1>With rsvg:</h1>
  
  <pre><code>rsvg-convert -a -w 200 -h 200 rect.svg &gt; rect-rsvg.png
  </code></pre>
  
  <p>START --</p>
  
  <p><a href="https://i.stack.imgur.com/UKXWX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UKXWX.png" alt="enter image description here"></a></p>
  
  <p>END --</p>
  
  <p><strong>Image is clear with correct aspect ratio, but I don't see a way to make it square (extend the image).</strong> </p>
  
  <p>Version:</p>
  
  <pre><code># rsvg-convert --version
  rsvg-convert version 2.40.9
  </code></pre>
  
  <h1>With Inkscape:</h1>
  
  <pre><code>inkscape -z -e rect-inkscape.png -w 200 -h 200 rect.svg
  </code></pre>
  
  <p>START --</p>
  
  <p><a href="https://i.stack.imgur.com/pseWt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/pseWt.png" alt="enter image description here"></a></p>
  
  <p>END --</p>
  
  <p><strong>Image is square and clear, but with incorrect aspect ratio.</strong> </p>
  
  <p>Version:</p>
  
  <pre><code># inkscape --version
  W: AppleCollationOrder setting not found, using AppleLocale.
  Setting LANGSTR from AppleLocale: en
  Overriding empty LANG from /usr/share/locale/locale.alias
  Setting Language: en_US.UTF-8
  Inkscape 0.48.5 r10040 (Jul 12 2014)
  </code></pre>