Batch convert SVG to PNG on Windows using Inkscape

Needed to convert several SVGs to PNG, and discovered the free Inkscape easily can be used in batch scripts.

The following .bat file will convert all SVGs dropped on it to a PNG with height 48 placed next to the original SVG. More options can be found in the Inkscape manual.

@echo off
for %%f in (%*) do (
    echo %%~f
    "C:\Program Files\Inkscape\inkscape.exe" ^
      -z ^
      --export-background-opacity=0 ^
      --export-height=48 ^
      --export-png="%%~dpnf.png" ^
      --file="%%~f"

)
  • Timothy Mills

    This was exactly what I wanted. Pretty accessible (I haven’t done Windows batch scripts for a couple of decades).

    I had to change the start of the for loop like so:

    for %%f in (*.svg) do (

    I changed %* in the parentheses to *.svg – it didn’t work with the %, and I wanted to explicitly limit it to SVG files (I have some others types of file in the directory that I want it to ignore).

    • %* just means “all given parameters”, so think you should be able to run the script with “script.bat *.svg”, or actually just drag’n’drop a stack of pngs onto the bat-file. But either way, good to hear you made it work for you and found it useful! 😀

      • Timothy Mills

        Oh, that makes sense. I was just setting it up so I could drop the script in the right folder and double-click it. But I see how that would make it more flexible if it’s being run from the command line, or from another script. Thanks!