DEV Community

Saulo Dias
Saulo Dias

Posted on • Updated on

Convert SVGs from Stroke to Path

I had to convert more than one thousand SVG files from stroke to path. That's because can't handle SVG files with strokes. Instead you have to provide the SVG files for your font containing only path elements.

This bash script does the job for you. You only need to install Inkscape and add it to the Windows PATH (C:\Program Files\Inkscape\bin in my case).

Then you run the script below in the folder with the SVG files.

mkdir -p _output

for i in *.svg
   inkscape --actions="select-all;selection-ungroup;select-all;selection-ungroup;select-all;object-stroke-to-path;" --export-filename=- $i > _output/$i
   echo "done with "$i
Enter fullscreen mode Exit fullscreen mode

GitHub Gist

The repeated actions are kind of a hack to make sure everything is ungrouped before we can convert it to path. You might get some error messages because of that, but that should not affect the end result.

Top comments (4)

ilijazm profile image
Ilijaz Mehmedovic

you are an absolute legend!

saulodias profile image
Saulo Dias

Glad to help!

mikael_pettersson_d554046 profile image
Mikael Pettersson

Ace, I signed up to in order to give you kudos!

saulodias profile image
Saulo Dias

Glad to hear that, man! Thanks!