Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a tool to convert SVG line paths from absolute to relative?

Tags:

svg

line

Looking for a tool to convert something like

M10 20L0 0 5 5 10 10

from the absolute position to relative, something like:

M10 20l-10 -20 5 5 5 5

Notice the uppercase L for absolute and lowercase l for relative?

like image 666
Kenneth Avatar asked Jul 31 '11 16:07

Kenneth


People also ask

Is absolute path better than relative path?

Relative links show the path to the file or refer to the file itself. A relative URL is useful within a site to transfer a user from point to point within the same domain. Absolute links are good when you want to send the user to a page that is outside of your server.

How do SVG paths work?

A path is defined in SVG using the 'path' element. The basic shapes are all described in terms of what their equivalent path is, which is what their shape is as a path. (The equivalent path of a 'path' element is simply the path itself.)


2 Answers

  1. Open Inkscape and select, File, Inkscape Preferences (or Shift + Ctrl + P )
  2. Select SVG output
  3. In the path data section untick Allow relative coordinates or select always use absolute coordinates depending on your version of inkscape.

    This will only affect newly created paths, or existing objects for which a rewrite of the path data is triggered. For existing paths

  4. Select Edit, then Select All in All Layers'.

  5. Use the arrow key to nudge the selection(e.g. one step up and one back down again). This will trigger a rewrite of the path data in 'd' which will follow the changed preferences for absolute path values.

This works for inkscape 0.48

like image 190
Derek Ewing Avatar answered Nov 08 '22 22:11

Derek Ewing


For who's still searching for this tool. There is one made by Lea Verou on codepen that convert paths to relative or absolute.

Example convert this:

M233.51,56.8c-0.57,0.24-1.33,0.52-2.28,0.86c-0.95,0.33-1.93,0.5-2.92,0.5s-1.84-0.27-2.53-0.82
c-0.69-0.55-1.03-1.49-1.03-2.82V36.25h7.85V28.9h-7.85V16.77h-9.56V28.9h-17.84V16.77h-9.56V28.9h-4.92v7.35h4.92v21.48
c0,1.67,0.26,3.08,0.79,4.25c0.52,1.17,1.22,2.12,2.1,2.85c0.88,0.74,1.9,1.27,3.07,1.61c1.16,0.33,2.41,0.5,3.75,0.5
c2.05,0,4-0.28,5.85-0.86c1.86-0.57,3.42-1.14,4.71-1.71l-1.93-7.56c-0.57,0.24-1.33,0.52-2.28,0.86c-0.95,0.33-1.93,0.5-2.92,0.5
c-1,0-1.84-0.27-2.53-0.82c-0.69-0.55-1.03-1.49-1.03-2.82V36.25h17.84v21.48c0,1.67,0.26,3.08,0.79,4.25
c0.52,1.17,1.22,2.12,2.1,2.85c0.88,0.74,1.9,1.27,3.07,1.61c1.16,0.33,2.41,0.5,3.75,0.5c2.05,0,4-0.28,5.85-0.86
c1.86-0.57,3.42-1.14,4.71-1.71L233.51,56.

Into this:

M233.51,56.8c-0.57,0.24,-1.33,0.52,-2.28,0.86c-0.95,0.33,-1.93,0.5,-2.92,0.5s-1.84,-0.27,-2.53,-0.82c-0.69,-0.55,-1.03,-1.49,-1.03,-2.82v-18.27h7.85v-7.35h-7.85v-12.13h-9.56v12.13h-17.84v-12.13h-9.56v12.13h-4.92v7.35h4.92v21.48c0,1.67,0.26,3.08,0.79,4.25c0.52,1.17,1.22,2.12,2.1,2.85c0.88,0.74,1.9,1.27,3.07,1.61c1.16,0.33,2.41,0.5,3.75,0.5c2.05,0,4,-0.28,5.85,-0.86c1.86,-0.57,3.42,-1.14,4.71,-1.71l-1.93,-7.56c-0.57,0.24,-1.33,0.52,-2.28,0.86c-0.95,0.33,-1.93,0.5,-2.92,0.5c-1,0,-1.84,-0.27,-2.53,-0.82c-0.69,-0.55,-1.03,-1.49,-1.03,-2.82v-18.28h17.84v21.48c0,1.67,0.26,3.08,0.79,4.25c0.52,1.17,1.22,2.12,2.1,2.85c0.88,0.74,1.9,1.27,3.07,1.61c1.16,0.33,2.41,0.5,3.75,0.5c2.05,0,4,-0.28,5.85,-0.86c1.86,-0.57,3.42,-1.14,4.71,-1.71l-1.97,-7.57z

https://codepen.io/leaverou/pen/RmwzKv

like image 45
Mattia Astorino Avatar answered Nov 09 '22 00:11

Mattia Astorino