通过命令行启用/禁用图层

问题描述 投票:0回答:2

我有一个脚本(如下),该脚本从svg文件导出到各种大小的png文件。这可行,但是我还需要更多。我需要能够在导出之前启用和禁用图层。因此,例如,在#Android行之后,我需要启用图层android并禁用图层ios

我该怎么做?

set -x

# Windows
INKSCAPE="/C/Program Files/Inkscape/inkscape.exe"
OPTS=--export-background-opacity=0

# Note that directories must already exist before exporting to them

SVG=My_Icon.svg
DEST=generated_icons

# Android
"$INKSCAPE" -w36 $OPTS --export-png=$DEST/android/ic_launcher-ldpi.png $SVG
"$INKSCAPE" -w48 $OPTS --export-png=$DEST/android/ic_launcher-mdpi.png $SVG
"$INKSCAPE" -w72 $OPTS --export-png=$DEST/android/ic_launcher-hdpi.png $SVG
"$INKSCAPE" -w96 $OPTS --export-png=$DEST/android/ic_launcher-xhdpi.png $SVG
"$INKSCAPE" -w144 $OPTS --export-png=$DEST/android/ic_launcher-xxhdpi.png $SVG
"$INKSCAPE" -w192 $OPTS --export-png=$DEST/android/ic_launcher-xxxhdpi.png $SVG
"$INKSCAPE" -w512 $OPTS --export-png=$DEST/android/ic_launcher-web.png $SVG

# iOS
"$INKSCAPE" -w57 $OPTS --export-png=$DEST/ios/ios_icon-57.png $SVG
"$INKSCAPE" -w72 $OPTS --export-png=$DEST/ios/ios_icon-72.png $SVG
"$INKSCAPE" -w114 $OPTS --export-png=$DEST/ios/ios_icon-57-2x.png $SVG
"$INKSCAPE" -w144 $OPTS --export-png=$DEST/ios/ios_icon-72-2x.png $SVG
svg inkscape
2个回答
0
投票

SVG只是XML,因此您可以设想一种工具,该工具可以按所需方式修改XML,将相关图层设置为in / visible。

也就是说,可能会有更方便的选项:通过CLI与Inkscape进行转换时,您可以声明要导出的XML节点的ID以及可以不呈现其他内容的标志。

从Inkscape的手册页:

-i,--export-id

导出的区域将由命名对象的边界框定义。导出的工程图将包括属于此边界框的任何其他对象。一个的名字可以通过从Inkscape中选择对象来找到给定的对象并查看XML编辑器。 (当然,如果这样做,您可能会使用“导出位图”对话框很好地导出。)

-j,--export-id-only

仅导出指定的对象。必须与--export-id选项一起使用。往上看。可以与--export-area-canvas和--export-area-page。

作为适当的参考,您可以在Inkscape中设置节点的ID。


0
投票

[我想出了一种使用xmlstarlet的方法,可以在将它传递给InkScape本身之前即时编辑InkScape SVG。

想象一下,您有一个具有SenateBackgroundCaesarAntonius三层的InkScape SVG,而您只需要组合(SenateBackground,Caesar)(SenateBackground,Antonius)

这是这样的层在SVG中的外观:

<g
 inkscape:label="Caesar"
 id="someID"
 inkscape:groupmode="layer"
 style="display:none"
 sodipodi:insensitive="true"
 transform="...">

仅作为旁注:在其他一些SO问题中,出现了使用inkscape --query-all <file> | grep "layer"查询图层的技巧,至少在我的发现中,这是不可靠的,因为inkscape并不总是命名[ C0]作为id="someID"id="layerX"查找)。对我来说,某些层只是获得了组ID,例如grep

要在参议院与凯撒一起生成PNG,现在需要执行这些步骤...

  1. 阅读SVG / XML可以通过g12345
  2. 完成
  3. 通过cat插入,显示参背景在我的示例中,我处理every层,因此我没有任何诸如在修改SVG时,请记住显示/隐藏保存之前的X / Y层,PNG生成脚本依赖于此!
  4. 再次将其插入xmlstarlet,显示凯撒
  5. 再次通过xmlstarlet将其放入,隐藏Antonius
  6. 将其放入InkScape,创建PNG您显然必须提供宽度/高度或DPI不会从文件中存储的设置中获取。

命令:

xmlstarlet

cat romanSenate.svg | \ xmlstarlet edit -P -S --update "//*[@inkscape:label='SenateBackground']/@style" -v "display:inline" | \ xmlstarlet edit -P -S --update "//*[@inkscape:label='Caesar']/@style" -v "display:inline" | \ xmlstarlet edit -P -S --update "//*[@inkscape:label='Antonius']/@style" -v "display:none" | \ inkscape -z -e romanSenate.svg.showingCaesar.png -d 300 /dev/stdin 指定输出DPI。我们使用-d 300作为输入文件,因为InkScape无法处理通过管道传递给它的任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.