0

I'm using a Windows batch script in Powershell to convert all numbered .svg files in a folder to .png, using Inkscape on the commandline, based on the answer to a previous question here.

@echo off
for %%i in ("%~dp0*.svg") do (
    echo %%i to %%~ni.png
    "C:\Program Files\Inkscape\bin\inkscape.com" --export-type="png" --export-background-opacity=1.0 "%%i"
)

The script calls Inkscape again for each file, which I suspect is the main speed bottleneck (I have many files to convert). I would prefer to call Inkscape once and provide the list of files to convert.

Is it possible to use --shell mode to do this? I cannot find an example that uses this approach.

feedMe
  • 3,431
  • 2
  • 36
  • 61
  • This is likely answered by product documentation. https://wiki.inkscape.org/wiki/index.php/Using_the_Command_Line#:~:text=Shell%20mode%20To%20open%20and%20edit%20multiple%20files,largely%20identical%20to%20those%20for%20the%20'normal'%20mode and https://gitlab.com/inkscape/inkscape/-/issues/640#note_268087574 – lit Feb 19 '21 at 22:34
  • Thank you I have read the documentation. The number of examples there is limited and didn't see an example for what I was hoping to do, but I worked it out and posted my own answer. – feedMe Feb 19 '21 at 23:01
  • it appears that Inkscape is an open source project. Anyone can change the code to do what they want. There may be sufficient interest that it can be contributed back into the package. https://inkscape.org/contribute/ – lit Feb 20 '21 at 01:40
  • Yes it is and they can. – feedMe Feb 20 '21 at 08:58
  • You can convert all SVG files in a directory to PNG using **ImageMagick** with `magick mogrify -format PNG *.svg` – Mark Setchell Feb 20 '21 at 09:56
  • @MarkSetchell there are other options than Inkscape for converting SVG to PNG, such as ImageMagick, but they often render it differently. I would like to use Inkscape for this. It also means that Inkscape-specific xml will be understood. – feedMe Mar 24 '21 at 22:15

2 Answers2

0

One approach I found was to use the interactive --shell mode with a sequence of "actions" and "verbs" such as this:

inkscape --shell
> file-open:file001.svg;export-filename:file001.png;export-do; file-open:file002.svg;export-filename:file002.png;export-do;

You can generate a long list of these action and verb sequences, one for each file. It works very well, but unfortunately I wasn't able to paste a large enough text string for the thousands of SVG files I wanted to convert. I think Powershell is limited by the amount of text you can paste into it, as is the usual command prompt.

Therefore it would be great if a future version of Inkscape accepted batch file containing such a list of commands. Currently it doesn't seem possible, as far as I can tell from the documentation.

feedMe
  • 3,431
  • 2
  • 36
  • 61
0

Following on from your own answer, I created a 10,000 line file called inkscape.cmd that looks like this:

inkscape-version
inkscape-version
inkscape-version
...
...

and ran it with:

inkscape --shell < inkscape.cmd

I have only tested this on macOS as I don't have Windows.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Did this sort you out, ok? – Mark Setchell Feb 23 '21 at 10:43
  • Thanks but no it didn't. In Windows at least, re-directing the file to Inkscape shell mode doesn't work correctly. I get an error `> Unable to find: file-open`. It only works if I go into interactive shell mode and paste in the commands, like I did in my answer. – feedMe Mar 24 '21 at 22:20