Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically convert SVG shapes to paths (lineto, moveto)

I have an SVG file coming from Inkscape, Illustrator, or any other application. I want to convert the shapes to lineto, moveto, curveto format.

What I want is something like:

./Appname svgfile outfilewithpath

I will give the SVG file as an argument, then my application will convert the object into the respective paths.

like image 902
skanzariya Avatar asked Mar 04 '13 14:03

skanzariya


People also ask

How do I export SVG to single path?

Copy the SVG and paste it into your favorite vector editor or save the SVG as a file and open it in your editor. Use the pen tool (pretty universal among all vector editors) and anywhere on a path (line) of the shape add a new anchor. With a single new anchor on any shape it will force it to be a path when you save.

How do I get SVG path in Figma?

Exporting Your Design as an SVG File Once you've created your design, it's time to export it as an SVG file. To do this, simply go to File > Export > Export As… and select Scalable Vector Graphics (SVG) from the drop-down menu. You can also choose whether you want to export your entire design or just a certain element.

Is it possible to draw any path in SVG?

It can draw anything! I've heard that under the hood all the other drawing elements ultimately use path anyway. The path element takes a single attribute to describe what it draws: the d attribute.


2 Answers

Inkscape has a command-line interface. Use the Inkscape man page along with the verb source for reference:

The ObjectToPath verb converts an object to a path:

inkscape filename.svg --select=myobject --verb=ObjectToPath --export-plain-svg=filename_to_path.svg

The export-text-to-path argument converts text nodes to paths:

inkscape filename.svg --export-eps=filename.eps --export-text-to-path

These are related questions on how to run InkScape from Perl, Ruby, PHP or Python:

  • Using the Inkscape shell from perl
  • Run inkscape in PHP
  • Calling Inkscape in Python
  • Inkscape Merge Ruby Gem
like image 87
Paul Sweatte Avatar answered Sep 18 '22 17:09

Paul Sweatte


This is what finally worked for me:

inkscape -f filename.svg --verb EditSelectAll --verb SelectionUnGroup --verb EditSelectAll --verb ObjectToPath --verb FileSave --verb FileQuit

It takes about 9 seconds to run and briefly opens the inkscape gui, which becomes the active application, so it's not ideal, but it's the only answer I could find that actually works.

like image 26
les_h Avatar answered Sep 16 '22 17:09

les_h