Is there any way to BATCH EXPORT SVGs to the PNG format?
- vector.rex
- Posts: 27
- Joined: Sat Feb 21, 2015 1:18 pm
Is there any way to BATCH EXPORT SVGs to the PNG format?
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!
Re: Is there any way to BATCH EXPORT SVGs to the PNG format?
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)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
- 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?
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 paths we'll use are:
So the script you'll be instructing me to use should look something like this (disregard color):
I've opened a DOS window and will need to perform the following:
*since they are of the inferior, non-scaleable PNG format they need to be BIG
The conventions we'll use are:
The @ symbol = a typed-in SPACE on the command line
The 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
or
C:/SOURCE@x@xxxx@xx@C:/OUTPUT@x
I've opened a DOS window and will need to perform the following:
- Navigate/Point DOS to the path C:\SOURCE
- Navigate/Point DOS to the path C:\OUTPUT
- INKSCAPE — If there is an option to define backround-color it should be Transparent
- INKSCAPE — The SVG files are all images
- INKSCAPE — The SVG images are different sizes
- INKSCAPE — The SVG images may include icons, and can be very small (16px Square)
- INKSCAPE — Regardless of the SVGs’ original sizes, all PNG resolutions will be 300 DPI*
*since they are of the inferior, non-scaleable PNG format they need to be BIG
Re: Is there any way to BATCH EXPORT SVGs to the PNG format?
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:
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.
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)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Re: Is there any way to BATCH EXPORT SVGs to the PNG format?
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
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
- 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?
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:
- open Windows DOS from inside Inkscape's program folder G:\GRAPHIX\Inkscape\
- The prompt starts in my profile directory C:\Documents and Settings\REX
- Type CD /D G:\GRAPHIX\Inkscape\
- Now in the directory containing inkscape.exe
- 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.
- 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?
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? ). 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 (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:
When double-clicked, INKY-SVG.bat begins operating on the 500 SVG files in
creating an element in Inkscape's program directory called
performing a "save as" operation on each SVG file
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.
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.
Re: Is there any way to BATCH EXPORT SVGs to the PNG format?
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
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
- 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?
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.