DEV Community

Saulo Dias
Saulo Dias

Posted on • Edited on

Convert SVGs from Stroke to Path

I had to convert more than one thousand SVG files from stroke to path. That's because IcoMoon.io 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.
bash stroke2path.sh

mkdir -p _output

for i in *.svg
do
   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
done
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)

Collapse
 
ilijazm profile image
Ilijaz Mehmedovic

you are an absolute legend!

Collapse
 
saulodias profile image
Saulo Dias

Glad to help!

Collapse
 
mikael_pettersson_d554046 profile image
Mikael Pettersson

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

Collapse
 
saulodias profile image
Saulo Dias

Glad to hear that, man! Thanks!