0

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
    Commented Aug 27, 2020 at 15:16

1 Answer 1

0

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
3
  • 1
    Aside: Depending upon the SVG renderer that ImageMagick is using, you may still be using Inkscape via Imagemagick if it is on your system. ImageMagick can use Inkscape, RSVG or its own internal MSVG/XML renderer. If Inkscape is on the system, then that will be used preferentially.
    – fmw42
    Commented Aug 29, 2020 at 1:00
  • 1
    Additional aside: imagemagick doesn't work with current Inkscape, as far as I know. gitlab.com/inkscape/inbox/-/issues/496 (cannot currently open links to GitHub, some kind of server outage)
    – Moini
    Commented Aug 30, 2020 at 20:38
  • (and, to be honest, the solution seems to be rather inexact. Providing a reply to my comment might have helped getting this solved in a more exact way)
    – Moini
    Commented Aug 30, 2020 at 20:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.