[Kde-games-devel] A simple svg optimizer

Luciano Montanaro mikelima at gmail.com
Wed Dec 19 20:18:33 CET 2007


Hi all,
I've been thinking for a while that we should do domething to reduce 
size/loading time for our SVG graphics, if possible, and yesterday evening I 
put together a small program to strip svg file of tags/attributes that are 
not affecting the final look.

At the moment the program is very simple, and does essentially two things:

It check the style elements of rects and paths, and removes redundand styles.
For example, if stroke:none; is set, all the stroke styles are removed. The 
same happens for the fill style.

It removes inkscape/sodipodi attributes from all the tags. These are not 
needed for rendering, but they are useful when editing the file again.

Oh, and since QDOM makes this easy, it removes indentation from the file.

I wrote the program as a filter, so it processes it input and puts the 
stripped svg to its stdout.

It has to be used as:

svgoptimize <in.svg >out.svg

or it can be used like 

gzip -dc <in.svgz | svgoptimize | gzip -9 -c >out.svgz

On my tigullio card deck, it reduces the file size from 703271 to 618907
which is not bad. If the file were compressed, the gain would be lower.

I tested it on the oxygen mimetype icons, and it makes them smaller too.

6356    mimetypes-orig
6044    mimetypes-optimized

I compressed the optimized icons with gzip -9, so the gain may be due in part 
to that.

As for the advantages of using it, well, mainly it's smaller file size.

I hoped it could improve svg loading in kgoldrunner, but I tested an optimized 
geek city theme, and it does not look like it makes a difference, at least on 
my laptop.

Anyway, for the curious, the sources are here:

http://www.cirulla.net/listing/kde_stuff/svgoptimize-0.0.tar.bz2

simply type

qmake
make

to compile it.

I think it may be useful to put the svgoptimize in the install step for our 
files. This way, we could deliver smaller packages, and distributions could 
ship more KDE games!

Ciao,
Luciano


More information about the kde-games-devel mailing list