Batch convert SVG images to desired size PNG or ICO [closed]

Solution 1:

ImageMagick has a command line tool that is available for Linux and Windows (and others). The converter tool is conveniently called "convert". Here's some usage documentation.

And here's where you can get a Windows installer.

Solution 2:

ImageMagick should not immediately associate to just any batch task involving images. Especially in this case where ImageMagick is poor solution for SVG conversion.

Better try Inkscape on command line:

inkscape in.svg --export-type=png --export-filename=out.png

Solution 3:

The command line did not work out of the box, plus I wanted 100 files to be converted. Here is how I made it work with windows 7:

  1. install inkscape - not the portable one!

  2. copy all your svg files in one folder, e.g. "C:\svgs\" there:

  3. you create a convert.bat file with this line inside:

    FOR %%A IN (*.svg) DO "C:\Program Files (x86)\Inkscape\inkscape.exe" --export-png=%%A.png
    

    (point to the correct folder of your installation):

  4. open the CMD as admin! To do so, hit the WIN key, type cmd, right click on "cmd.exe" and select "Run as administrator".

  5. navigate to your "C:\svgs\" and type convert.bat -- All svg-files will be converted to PNGs.

  6. Use Windows Explorer to search for the converted PNG files. On my PC they were in folder: C:\Users\myname\AppData\Local\VirtualStore\Program Files (x86)\Inkscape\svgs

Hope that helps.


As the resolution for the command line could only be set fixed as far as I could see, I ended up using the InkscapeBatch tool. There I could set the DPI to increase all images relatively.

You need to specify the correct settings or it will not work. Here is what I did:

enter image description here

enter image description here

After you hit "Finish", you need to press the button "Start batch converter..." in the toolbar:

enter image description here

Solution 4:

For SVG to PNG conversion I found cairosvg (https://cairosvg.org/) performs better than ImageMagick. Steps for install and running on all files in your directory.

pip3 install cairosvg

Open a python shell in the directory which contains your .svg files and run:

import os

for file in os.listdir('.'):
    name = file.split('.svg')[0]
    cairosvg.svg2png(url=name+'.svg',write_to=name+'.png') 

This will also ensure you don't overwrite your original .svg files, but will keep the same name. You can then move all your .png files to another directory with:

$ mv *.png [new directory]