0

I've got the outline of a simple shape in a png. Is there a tool or technique for converting this to a TikZ outline that I can stroke with different colors and line widths etc?

Online "vectorizer" png-to-svg tools work fine for producing an svg, but I haven't had any success including the svg. My next try will be manually rewriting the svg as TikZ paths, but I wanted to ask here first if this is a solved problem.

enter image description here

Anna
  • 811
  • You can use e.g. inkscape to convert the shape to svg, clean it up as needed and then convert it to tikz using svg2tikz (this is also avilable as plugin for inkscape, so you can do everything in one place) – samcarter_is_at_topanswers.xyz Jan 28 '24 at 11:57
  • Alternatively you could directly use the source of the in a tikzpicture with the svg.path library. – samcarter_is_at_topanswers.xyz Jan 28 '24 at 11:59
  • Thank you @samcarter_is_at_topanswers.xyz, I'll give it a try with the Inkscape plugin. I've tried svg.path earlier, and didn't manage to get it to follow the path properly. – Anna Jan 28 '24 at 12:01
  • Another option is to manually draw the tikz path. Your image could probably created with 6 points, rounded corners and in/out operators for the curvy bits. This way you would get good quality tikz code. – samcarter_is_at_topanswers.xyz Jan 28 '24 at 12:03
  • @samcarter_is_at_topanswers.xyz That seems pretty hard. I can position the corners, but finding e.g. Bezier parameters seems like it would take a lot of trial and error while drawing the result over the original bitmap to compare. Is that what you mean? Anyway, it seems Inkscape includes a powerful bitmap tracer, so I'm sure that together with the svg2tikz plugin will work fine. Thanks for your advice! – Anna Jan 28 '24 at 12:08
  • Here a rough sketch to draw it manually: \draw[rounded corners=0.1cm] (-0.5,2.1) to[in=45,out=225] (-1.4,-1) -- (-1,-2.2) -- (1,-2.2) -- (1.4,-1) to[in=-45,out=135] (0.5,2.1) -- cycle; (the exact coordinates and angles need some fine tuning, but it should be enough to get you started) – samcarter_is_at_topanswers.xyz Jan 28 '24 at 12:19
  • Thank you very much! – Anna Jan 28 '24 at 12:20
  • If you would like to learn how to manually redraw an existing curve in tikz, the book https://tug.org/books/reviews/tb138reviews-kottwitz-tikz.html has a step-by-step tutorial for this. – samcarter_is_at_topanswers.xyz Jan 28 '24 at 12:26
  • (a bit closer approximation: \draw[rounded corners=0.05cm,red] (-0.4,2.18) to[in=35,out=205,in looseness=0.7] (-1.38,-0.9) -- (-1.08,-2.15) -- (1.08,-2.15) -- (1.38,-0.9) to[in=-25,out=145,out looseness=0.7] (0.4,2.18) -- cycle;) – samcarter_is_at_topanswers.xyz Jan 28 '24 at 12:34

0 Answers0