0

I know the title is sort of confusing but I really don't know how to describe it better. I will first visualize what I want to achieve, because it becomes really clear then.

The following image is a screenshot of my "outer" stroke SVG. It has a green stroke (purely for visualizing where the stroke is) and a black filling: picture of "outer" stroke

What I want to achieve is convert this "outer" stroke into an "inner" stroke, where there is no filling, but a single stroke with a matching stroke width so that they are visually equivalent. Here is what I want to have (green is depicting the stroke again to make clear where the stroke would be, there is no filling, roughly sketched):

picture of "inner" stroke

My question therefore is: is there any way in Illustrator or Inkscape or any other tool to trace the "inner" stroke? A straight SVG ("outer" stroke) -> SVG ("inner" stroke) conversion would be preferred, but I would not know how. I would be fine with rasterizing my SVG first and then tracing the "inner" stroke of the resulting PNG, so SVG ("outer" stroke) -> PNG -> SVG ("inner" stroke).

I need to do this with multiple thousands of SVGs, which is why manual tracing is not an option.

Does anyone have any pointers for me or has even done this before? Thankful for any help!

1
  • Not really. There are methods to generate a single stroke such as centre-line tracing a raster image, however results are rarely perfect. see example in Inkscape. To be honest, it might more efficient to redraw strokes on top of your existing graphic manually. You can also do an offset path effect, but that would still generate a closed path, and you need to delete one edge of it, which would be messy and time consuming
    – Billy Kerr
    Commented Oct 18, 2023 at 9:50

1 Answer 1

0

This is not a trivial problem to solve, however Inkscape has a 'Centerline tracing' mode for the 'Path → Trace Bitmap...' tool, that may help create adequate approximations. You'll probably have to play around with the sliders a bit and clean them up with the node-tool afterwards, to get good results.

Inkscape's 'Trace Bitmap' panel with 'Centerline tracing' detection mode selected.

Also, instead of exporting as PNGs and re-importing, you can use 'Edit → Make a Bitmap Copy' with your objects selected, to directly convert them to an image object that you can trace.

2
  • Wow, this is exactly what I was looking for! Also, I finally have a name for that now, centerline tracing. I just tried it out and the results are not perfect but might suffice for my purposes. Do you know if I can automate this somehow? I have used Illustrator Actions and batch processing before. I also heard Inkscape has a command line tool (I am a programmer, so that would be fine). Could I automate these steps with Inkscape command line tool somehow? Commented Oct 18, 2023 at 9:54
  • Found it myself - I think they use autotrace under the hood (says that in your screenshot) so I can use the code from autotrace directly: github.com/autotrace/autotrace Haven't tried yet, but should be possible and much more convenient than working around Inkscape. You helped me very much, thanks! Commented Oct 18, 2023 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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