问题描述
我有一个由主要轮廓形状和文本组成的SVG,我想将其转换为“模版”,在该模版中从主图像中切出文本(文本为模版字体)。
我在Inkscape GUI中手动完成了该过程,将文本转换为路径,使用Union将所有字母组合成一个路径,然后使用Path-Exclude从主轮廓中剪切文本路径。
现在,我想通过Inkscape命令行自动化此过程,将结果导出为位图/ PNM图像(它将转换为带有Potrace的DXF)。但是我似乎找不到正确的Inkscape CLI命令。
这是在Windows 10上。
解决方法
我发现了一种更简单的方法来完成此任务,完全避免了Inkscape的问题:
使用imagemagick
将源SVG(带有嵌入文本)转换为中间的B&W PNM图像,然后使用potrace
将其转换为DWG(或平面SVG):
#!/usr/bin/env bash
# Convert monochrome SVG to cuttable DWG
# potrace manpage: http://potrace.sourceforge.net/potrace.1.html
declare magick='/c/Program Files/ImageMagick-7.0.10-Q8/magick.exe'
declare potrace='/c/Program Files/potrace-1.16.win64/potrace.exe'
declare input_svg="${0%/*}/SVG/test-input.svg"
declare intermediate="${0%/*}/SVG/intermediate.pnm"
declare output="${0%/*}/SVG/test.svg"
declare idim=2000x2000 # dimensions of intermediate pixel file
declare -a potrace_opts=(
--backend svg # output type: svg|dxf
--flat # for SVG
--tight # No margins,trim surrounding whitespace
--width 8in
#--height 16in
#--resolution 20 # dpi - for dimension-based backends
#--scale 0.1 # for pixel-based backends
--opttolerance 0.1 # default 0.2. Larger values allow more consecutive Bezier curve segments to be joined together in a single segment,at the expense of accuracy.
--alphamax 1.08 # corner threshold (default 1); smaller=more sharp corners; 0=output is a polygon; >1.33 = output is completely smooth.
)
"$magick" convert -size $idim "$input_svg" "$intermediate" || exit
"$potrace" "${potrace_opts[@]}" "$intermediate" -o "$output" || exit