Page MenuHomePhabricator

Minimize SVG output
Closed, ResolvedPublic


The SVG produced by MathJax is a bit verbose. It is possible to reduce the size using tools like scour (apt-get install python-scour):

scour --indent=none --shorten-ids -i /tmp/test.svg -o /tmp/test.scoured.svg

ls -lh /tmp/test*
-rw-r--r-- 1 gabriel gabriel 20K Oct 26 21:42 /tmp/test.svg
-rw-r--r-- 1 gabriel gabriel 15K Oct 26 22:05 /tmp/test.scoured.svg

After gzip -9 on each of the SVG files:
-rw-r--r-- 1 gabriel gabriel 7.3K Oct 26 21:57 /tmp/test.svg.gz
-rw-r--r-- 1 gabriel gabriel 5.5K Oct 26 22:05 /tmp/test.scoured.svg.gz

So about a 25% reduction of the compressed size, I believe without any quality loss.

There is a partial port of scour to JS (, but it does miss the crucial path simplification pass from scour.

Version: unspecified
Severity: normal


Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:52 AM
bzimport added a project: Mathoid.
bzimport set Reference to bz72547.
bzimport added a subscriber: Unknown Object (MLST).

I got even better results with, which is already a node module.

svgo --disable=removeUselessStrokeAndFill -i /tmp/test.svg -o /tmp/test.svgo.svg

-rw-r--r-- 1 gabriel gabriel 14K Oct 26 22:26 /tmp/test.svgo.svg
-rw-r--r-- 1 gabriel gabriel 5.3K Oct 26 22:27 /tmp/test.svgo.svg.gz

We can just drop this into mathoid as-is.

Change 278881 had a related patch set uploaded (by Esanders):
Compress SVG output with SVGO

Change 278881 merged by jenkins-bot:
Compress SVG output with SVGO

Physikerwelt claimed this task.