Is there any way to BATCH EXPORT SVGs to the PNG format?

Other sites and resources for Inkscape users.
User avatar
vector.rex
Posts: 27
Joined: Sat Feb 21, 2015 1:18 pm

Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby vector.rex » Wed Jul 13, 2016 10:50 am

I have over 500 SVG files I need to convert to the PNG format. I can't afford to purchase a converter so I've been trying out the (very few) free utilities out there, but they either don't work -or- they ask me to pre-define an output size. :? But that's the problem: each of these files is a different size. Any help would be greatly appreciated!! Thank you!

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby Moini » Wed Jul 13, 2016 9:32 pm

Yes, of course. See https://inkscape.org/en/doc/inkscape-man.html for the command line reference.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
vector.rex
Posts: 27
Joined: Sat Feb 21, 2015 1:18 pm

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby vector.rex » Thu Jul 14, 2016 7:28 am

Moini, thank you. I'm afraid I'm not very good with DOS. :? I know how to pull up the DOS window, it's what I type in that I'm not certain about, so forgive me if the following is overly explicit . . .

The conventions we'll use are:
The @ symbol = a typed-in SPACE on the command line
The :arrow: dingbat = ENTER (carrier return)

The paths we'll use are:
C:\SOURCE = The folder containing 500 SVG images and no other files or sub-folders
C:\OUTPUT = The destination folder for the generated PNG files

So the script you'll be instructing me to use should look something like this (disregard color):
xxxx@xx@C:/SOURCE @x@xxxx@xx@xxxxxxx :arrow:
or
C:/SOURCE@x@xxxx@xx@C:/OUTPUT@x :arrow:

I've opened a DOS window and will need to perform the following:
  1. Navigate/Point DOS to the path C:\SOURCE
  2. Navigate/Point DOS to the path C:\OUTPUT
  3. INKSCAPE — If there is an option to define backround-color it should be Transparent
  4. INKSCAPE — The SVG files are all images
  5. INKSCAPE — The SVG images are different sizes
  6. INKSCAPE — The SVG images may include icons, and can be very small (16px Square)
  7. INKSCAPE — Regardless of the SVGs’ original sizes, all PNG resolutions will be 300 DPI*
Moini, if you have other options you think I might be interested in — or advice on how to structure/rethink SVG conversions generally — please let me know. My bank account doesn't afford me the luxury of purchasing a program to do these SVG-to-PNG batch conversions for me, so I am here to learn from you (and everyone on this wonderful forum). The more I learn about SVG the greater my respect for the format.

*since they are of the inferior, non-scaleable PNG format they need to be BIG

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby Moini » Thu Jul 14, 2016 11:20 am

Sorry, I don't know how to write .bat files for Windows or how to use the Windows command line, I'm a long-time Linux user - I *could* write a bash script or a python program, but that won't help you, of course.

The command for a single image would be:

Code: Select all

inkscape -f imagename.svg -e imagename.png -d 300 -y 0.0


where -d is for the dpi value, and -y sets the background opacity.

From here, I hope that either a Windows user or maybe a websearch will help you.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby v1nce » Thu Jul 14, 2016 7:21 pm

not tested

combining with http://stackoverflow.com/questions/1807 ... tch-script

open a dos box and make sure you are into the directory[*] that hold inkscape.exe using cd path_to_directory
(or replace inkscape with "path_to_directory/inkscape" in the following command)
(or add the path of inkscape in the PATH global environment variable)

for /f "usebackq delims=|" %%f in ('dir /b "path_of_the_source_directory"') do inkscape -f %%f -e %%f.png -d 300 -y 0.0

your converted files wil be in the same directory named *.svg.png

* don't know what it is ; probably c:\program files\inkscape\bin

User avatar
vector.rex
Posts: 27
Joined: Sat Feb 21, 2015 1:18 pm

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby vector.rex » Fri Jul 15, 2016 2:53 am

v1nce . . . thank you for helping me with this. Inkscape lives in partition "G" (Graphics) on my hard drive. The full program path is G:\GRAPHIX\Inkscape\inkscape.exe Here is exactly what I attempted using your example:

  1. open Windows DOS from inside Inkscape's program folder G:\GRAPHIX\Inkscape\
  2. The prompt starts in my profile directory C:\Documents and Settings\REX
  3. Type CD /D G:\GRAPHIX\Inkscape\
  4. Now in the directory containing inkscape.exe
  5. Typing this string:

    Code: Select all

    for /f "usebackq delims=|" %%f in ('dir /b "C:\SOURCE"') do inkscape -f %%f -e %%f.png -d 300 -y 0.0

    I get the following error:

    Code: Select all

    %%f was unexpected at this time.
As you can see I hunted down the command to change to Inkscape's program directory (above, blue) but beyond that I don't have a clue what I'm doing . . . :?:

User avatar
vector.rex
Posts: 27
Joined: Sat Feb 21, 2015 1:18 pm

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby vector.rex » Fri Jul 15, 2016 6:09 am

Okay I've had a (minor) breakthrough. It dawned on me that v1nce's original script was meant to be the actual batch file itself (alright, but I did say I'm not good with DOS yeah? :lol: ). The name I gave it is INKY-SVG.bat, and after one or two tweaks I saved it in Inkscape's program folder. Double-clicking INKY-SVG.bat actually activates something :shock: (hey, I'm just as shocked as you lol) and you can watch it in DOS working its way through each file. What it doesn't do is actually create any .PNGs. So first, here is v1nce's (modified) code:

Code: Select all

for /f "usebackq delims=|" %%f in ('dir /b "C:\SOURCE\*.svg"') do inkscape -f %%f -e %%f.png -d 300 -y 0.0

When double-clicked, INKY-SVG.bat begins operating on the 500 SVG files in

Code: Select all

C:\SOURCE

creating an element in Inkscape's program directory called

Code: Select all

dir

performing a "save as" operation on each SVG file

Code: Select all

Bitmap saved as: dir

and systematically overwriting each "dir" with the same name, as you can see in my attached screenshot of the tail-end of INKY's operation. I sense I'm close; let me know what else to change, and thank you everyone.


INKY-SVG-BAT.png
INKY-SVG-BAT.png (87.13 KiB) Viewed 13748 times

v1nce
Posts: 696
Joined: Wed Jan 13, 2010 4:36 am

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby v1nce » Fri Jul 15, 2016 9:09 am

Sorry don't have any acces to windows for now. So it will be difficult to help.

anyway could you post the output of

for /f "usebackq delims=|" %%f in ('dir /b "C:\SOURCE\*.svg"') do echo %%f

if it prints the full path of all input svg then we're on the right track

then try

for /f "usebackq delims=|" %%f in ('dir /b "C:\SOURCE\*.svg"') do echo %%f.png
or maybe
for /f "usebackq delims=|" %%f in ('dir /b "C:\SOURCE\*.svg"') do echo "%%f.png"

if it outputs path of (non-existent) *.svg.png

the aim of the game is to get full path of the files and then feed this into the
inkscape -f full_path_to_input.svg -e full_path_to_output.svg -d 300 -y 0.0

User avatar
vector.rex
Posts: 27
Joined: Sat Feb 21, 2015 1:18 pm

Re: Is there any way to BATCH EXPORT SVGs to the PNG format?

Postby vector.rex » Sat Jul 16, 2016 3:10 am

v1nce wrote:
If [this] prints the full path of all input svg then we're on the right track:

Code: Select all

for /f "usebackq delims=|" %%f in ('dir /b "C:\SOURCE\*.svg"') do echo %%f


:? v1nce, it doesn't . . .

Code: Select all

%%f was unexpected at this time.

I get that one line — triggered once from my direct input of your string (above) while in path G:\GRAPHIX\Inkscape\ — and to be absolutely certain I typed it in 3 different times: same outcome.


Return to “Inkscape Resources”