0
votes

I have an SVG that consists of a main outline shape plus text, that I want to convert into a "stencil" where the text is cut out from the main image (the text is in a stencil font).

I went through the process manually in the Inkscape GUI, converting the text to paths, using Union to combine all the letters into a single path, then using Path-Exclude to cut the text path from the main outline.

Now I want to automate this process through the Inkscape command line, exporting the result as a bitmap/PNM image (which will get converted to a DXF with potrace). But I can't seem to find the correct Inkscape CLI commands for this.

This is on Windows 10.

1
Where did you look and what did you find? - Moini

1 Answers

0
votes

I found a much easier way to accomplish this, avoiding Inkscape entirely:

Use imagemagick to convert the source SVG (with embedded text) into an intermediate B&W PNM image, then use potrace to convert that to a DWG (or a flat 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