Svg 通过命令行启用/禁用图层
我有一个脚本(如下),它可以从svg文件导出到各种大小的png文件。这很有效,但我需要更多。在导出之前,我需要能够启用和禁用图层。 因此,例如,在#Android行之后,我需要 启用层android并禁用层ios 我该怎么做Svg 通过命令行启用/禁用图层,svg,inkscape,Svg,Inkscape,我有一个脚本(如下),它可以从svg文件导出到各种大小的png文件。这很有效,但我需要更多。在导出之前,我需要能够启用和禁用图层。 因此,例如,在#Android行之后,我需要 启用层android并禁用层ios 我该怎么做 set -x # Windows INKSCAPE="/C/Program Files/Inkscape/inkscape.exe" OPTS=--export-background-opacity=0 # Note that directories must alre
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只是一种XML,因此您可以设想一种工具,以您想要的方式修改XML,将相关层设置为in/visible 也就是说,可能有更方便的选项:当通过CLI使用Inkscape进行转换时,您可以声明要导出的XML节点的ID以及不呈现任何其他内容的标志 从Inkscape的手册页: -i、 --导出id 导出的区域将由命名对象的边界框定义。导出的图形将包括以下部件: 在此边界框内的任何其他对象。名字 通过从Inkscape中选择对象,可以找到给定对象 看看XML编辑器。(当然,如果你这样做,你可以 使用“导出位图”对话框导出。) -j、 --仅限导出id 仅导出指定的对象。必须与--export id选项一起使用。见上文。可用于 --导出区域画布和--导出区域页面
为了获得正确的参考,您可以从Inkscape中设置节点的ID。我提出了一种方法,在将Inkscape SVG传递给Inkscape本身之前,使用
xmlstarlet
动态编辑Inkscape SVG
假设您有一个具有三层的InkScape SVG,SenateBackground
,Caesar
和Antonius
,您只需要组合(SenateBackground,Caesar)
和(SenateBackground,Antonius)
这就是SVG中该层的外观:
<g
inkscape:label="Caesar"
id="someID"
inkscape:groupmode="layer"
style="display:none"
sodipodi:insensitive="true"
transform="...">
-d300
指定输出DPI。我们使用/dev/stdin
作为输入文件,因为InkScape不处理通过管道传输到它的任何内容
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