How to save SVG file with Inkscape CLI?

放肆的年华 提交于 2019-12-04 20:27:02

问题


I'm working with Inkscape in cli no (--without-gui or -z) to :

  1. Select multiple nodes by id (hanzi, pinyin) ;
  2. Create an union of them ;
  3. Save as a new file (test-union-cli.svg).

Command

So I use this command:

inkscape -z -f ./䖠-x45A0.svg \
    --select=hanzi --select=pinyin \
    --verb SelectionUnion --verb FileSaveCopyAs \
    --verb=FileClose test-union-cli.svg

Output error

** (inkscape:27462): CRITICAL *: Inkscape::XML::Document sp_repr_read_file(const gchar*, const gchar*): assertion `Inkscape::IO::file_test( filename, G_FILE_TEST_EXISTS )' failed

** (inkscape:27462): CRITICAL *: Inkscape::XML::Document sp_repr_read_file(const gchar*, const gchar*): assertion `Inkscape::IO::file_test( filename, G_FILE_TEST_EXISTS )' failed

** (inkscape:27462): WARNING **: Specified document test-union-cli.svg cannot be opened (does not exist or not a valid SVG file)

The file test-union-cli.svg is not supposed to exists. So what am I doing wrong here?


回答1:


tl;dr

  1. You can't save to a different file than the one open. So edit a copy ;
  2. Verb need the GUI, don't use -z or --without-gui.

Verbs don't take parameters

Asked on #inkscape and it come out that currently (Inkscape 0.48.3.1 r9886 (Jan 29 2013)) doesn't support verb's parameters:

verbs do not take arguments -> you cannot save a file you opened with '-f' under a different name copy the file first (e.g. in the script), and edit and save the copied file

There is a bug confirmed on this topic (see: Bug:Provide scriptable method of saving files).

Verb imply GUI

verbs currently (with stable) always require to open the GUI (even if no interaction is required)

Bug is confirmed Allow suppressing the GUI (-z) when using --verb option(s) and added to whishlist.

Temporary Solution

Newer version of Inkscape may fix this "issue", currently you can solve it by doing

cp 䖠-x45A0.svg test-union-cli.svg && inkscape -g -f ./test-union-cli.svg \
    --select=hanzi --select=pinyin --verb=SelectionUnion \
    --verb=FileSave --verb=FileClose

Hope (v.049)

Improvement is on its way lp:~7-eric/inkscape/effectscript:

read the commit log of revision 12388 here https://code.launchpad.net/~7-eric/inkscape/effectscript - this was merged into trunk recently, and AFAIU allows to run boolops verbs via cli without GUI -> likely the next major version of inkscape (0.49) will have better cli support



来源:https://stackoverflow.com/questions/18630229/how-to-save-svg-file-with-inkscape-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!