No Server, Zero Dependencies
One good thing about svg2png is that the computations are all done in the browser. So compared to other online services (e.g. this), there are no file upload limits. Also, svg2png lives on the web, so there is no need to download any thing (instead of a modern browser) before using it.
How It Works?
I used HTML5’s
<input type='file' multiple> to let users upload their SVGs. After that, the files are converted into object URLs. This allows me to load the SVG images (invisibly) with
<img src=objectURL>, so I can get the information of these images (height and width).
The trick to adjust the DPI of the output PNG is by scaling the height and width of the canvas, which is handily provided by the
scaleHeight options in
canvg(). But since I have no way to get the size information of the original image directly from the File object retrieved from
<input type='file'>, I have to load the SVG images with the
<img> tags first.
The source code of this simple project can be found here on GitHub.