Page MenuHomePhabricator

Minimize SVG output
Closed, ResolvedPublic

Description

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 (https://github.com/preciousforever/SVG-Cleaner), but it does miss the crucial path simplification pass from scour.


Version: unspecified
Severity: normal

Details

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 https://github.com/svg/svgo, 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.

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJul 21 2015, 10:23 PM
Restricted Application added a subscriber: StudiesWorld. · View Herald TranscriptNov 29 2015, 2:06 PM

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

https://gerrit.wikimedia.org/r/278881

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

https://gerrit.wikimedia.org/r/278881

Physikerwelt closed this task as Resolved.Apr 7 2016, 3:30 PM
Physikerwelt claimed this task.
Aklapper added a project: Math.Jun 24 2020, 5:53 AM