Reduce SVG file size by removing unnecessary attributes
Bug #171983 reported by
Bug Importer
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Inkscape |
Triaged
|
Medium
|
Unassigned | ||
inkscape (Debian) |
Confirmed
|
Unknown
|
|||
inkscape (Ubuntu) |
Triaged
|
Low
|
Unassigned |
Bug Description
When Inkscape saves an SVG file, even in Plain SVG mode, it leaves a lot of
unnecessary attributes in the XML file, which increase file size. For
example, all objects have a style attribute which specifies values for many
CSS attributes such as marker, opacity, stroke-dasharray, etc. even if it
is specifying the default values. If a CSS attribute is not needed because
it is set to the default value according to the SVG spec, it should be
omitted. Also, Inkscape adds an "id" attribute to all objects, even if it
is just a generic value like "path2042" that hasn't been changed by the
user. Is this really needed?
<email address hidden>
Changed in inkscape: | |
importance: | Undecided → Medium |
status: | New → Confirmed |
tags: | added: svg |
Changed in inkscape: | |
status: | Confirmed → In Progress |
Changed in inkscape: | |
status: | In Progress → Confirmed |
Changed in inkscape (Ubuntu): | |
status: | New → Confirmed |
Changed in inkscape (Debian): | |
status: | Unknown → Confirmed |
tags: | added: patch-forwarded-upstream |
Changed in inkscape (Ubuntu): | |
importance: | Undecided → Low |
status: | Confirmed → Triaged |
Changed in inkscape: | |
status: | Confirmed → Triaged |
To post a comment you must log in.
This patch done against SVN as of 1 March 2009.
I've put in a draft of a quick-n-dirty filter that optimizes some known defaults out of the style="" attributes. This is done only at the final saving time. It can be made smarter by working against a known SVG schema version number, in case any schema specifies different default style values.
Only style="" attributes are filtered. If stroke:none, don't save any stroke-X:Y parts. Same with fill:none and marker:none. Other known defaults are skipped based on a short list hardcoded into the function for now.
I get about 25% savings on file size on a path-heavy SVG file. Let me know [ e d @ h a l l e y . c c ] if there are any problems.