25 January 2008

Unbloat your Inkscape made SVGs

This should be common knowledge, but I see it often not used, so maybe a blog post will increase the awareness a bit.

Long story short: when trying to fit all the packages on a live CD every bit matters, so a number of strangely large file size for some SVG icons got noticed: a directory with 50 icons, 3.0 MB (in g-p-m, if that matters). Puff: run a "magic" script (an one liner), the size is decreased to 986.0 KB, the new version is commited upstream and everybody is happy!
It looks like a good idea for everyone using SVG icons to "unbloat" them, the space saved may be significant.

As any Inkscape user that's wort his salt should already know, the script is something like this:

for i in *.svg; do inkscape -f "$i" --vacuum-defs --export-plain-svg "$i"; done


Or, for one single file from the GUI, File > Vacuum Defs and save as Plain SVG.

Now some boring details: when working for a long time on a complex document Inkscape may vreate a lot of definitions and some of them may get ununsed, like you fill an object with a gradient and delete the object later. The gradient definition is kept, you may want to reuse it later, so a complex file may gather a lot of such unused definitions (even more if you import another files, each with its duplicate or unused definitions). Vacuuming them is a good idea, it may reduce the file size.

Another (small) file size reduction can be achieved by saving as "plain" SVG. By default, Inkscape will put inside the SVG some atributes useful (but not essential) for further editing (window geometry, guides, metadata and so on). Saving as "plain" SVG will remove them.

One of the worst offender was initially 281.1 KB, it decreased to 56.4 KB after vacuum defs and to 48.6 after saving as plain SVG.

4 comments:

  1. I suspected the "Vacuum" option would do that, but I never tried to test it, nor I attempted to read the description of the function in the manual.

    Now I can confirm that my hunch was correct, thanks :-)

    ReplyDelete
  2. Thanks nicu. That's really helpful advice!

    ReplyDelete
  3. the examples folder on the desktop of the Ubuntu live CD should also have an SVG file

    ReplyDelete
  4. Thanks a lot. 2.5MB -> 400k, sorted!
    Russ.

    ReplyDelete