【问题标题】:Inkscape: Convert SVG with text to a stencil image, from command line CLIInkscape:从命令行 CLI 将带有文本的 SVG 转换为模板图像
【发布时间】:2020-08-27 01:01:26
【问题描述】:

我有一个由主轮廓形状和文本组成的 SVG,我想将其转换为“模板”,其中文本从主图像中剪切出来(文本采用模板字体)。

我在 Inkscape GUI 中手动完成了该过程,将文本转换为路径,使用 Union 将所有字母组合成一个路径,然后使用 Path-Exclude 将文本路径从主轮廓中剪切出来。

现在我想通过 Inkscape 命令行自动执行此过程,将结果导出为位图/PNM 图像(将通过 potrace 转换为 DXF)。但我似乎无法为此找到正确的 Inkscape CLI 命令。

这是在 Windows 10 上。

【问题讨论】:

  • 你在哪里看?发现什么?

标签: svg command inkscape


【解决方案1】:

我找到了一种更简单的方法来实现这一点,完全避免使用 Inkscape:

使用 imagemagick 将源 SVG(带有嵌入文本)转换为中间黑白 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

【讨论】:

  • 旁白:根据 ImageMagick 使用的 SVG 渲染器,如果系统上存在 Inkscape,您可能仍会通过 Imagemagick 使用 Inkscape。 ImageMagick 可以使用 Inkscape、RSVG 或它自己的内部 MSVG/XML 渲染器。如果系统上有 Inkscape,则将优先使用它。
  • 补充一点:据我所知,imagemagick 不适用于当前的 Inkscape。 gitlab.com/inkscape/inbox/-/issues/496(目前无法打开指向 GitHub 的链接,某种服务器中断)
  • (老实说,解决方案似乎相当不准确。回复我的评论可能有助于以更准确的方式解决此问题)
猜你喜欢
  • 1970-01-01
  • 2016-04-16
  • 1970-01-01
  • 1970-01-01
  • 2021-05-22
  • 1970-01-01
  • 2022-01-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多