With the current code, scour could do a pointless remap of an ID, where there is no benefit in it. Consider: ```xml <?xml version="1.0" encoding="UTF-8"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <rect id="a" width="80" height="50" fill="red"/> <rect id="b" width="80" height="50" fill="blue"/> </defs> <use xlink:href="#a"/> <use xlink:href="#b"/> <use xlink:href="#b"/> </svg> ``` In this example, there is no point in swapping the IDs - even if "#b" is used more often than "#a", they have the same length. Besides a performance win on an already scour'ed image, it also mean scour will behave like a function with a fixed-point (i.e. scour eventually stops altering the image). To solve this, we no longer check whether an we find exactly the same ID. Instead, we look at the length of the new ID compared to the original. This gives us a slight complication as we can now "reserve" a "future" ID to avoid the rename. Thanks to Eduard "Ede_123" Braun for providing the test case. Signed-off-by: Niels Thykier <niels@thykier.net> |
||
|---|---|---|
| scour | ||
| unittests | ||
| .gitignore | ||
| .travis.yml | ||
| CONTRIBUTING.md | ||
| HISTORY.md | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
| scour.sublime-project | ||
| setup.py | ||
| testcss.py | ||
| testscour.py | ||
| tox.ini | ||
Scour
Scour is an SVG optimizer/cleaner that reduces the size of scalable vector graphics by optimizing structure and removing unnecessary data written in Python.
It can be used to create streamlined vector graphics suitable for web deployment, publishing/sharing or further processing.
The goal of Scour is to output a file that renderes identically at a fraction of the size by removing a lot of redundant information created by most SVG editors. Optimization options are typically lossless but can be tweaked for more agressive cleaning.
Scour is open-source and licensed under Apache License 2.0.
Scour was originally developed by Jeff "codedread" Schiller and Louis Simard in in 2010. The project moved to GitLab in 2013 an is now maintained by Tobias "oberstet" Oberstein and Eduard "Ede_123" Braun.
Installation
Scour requires Python 2.7 or 3.3+. Further, for installation, pip should be used.
To install the latest release of Scour from PyPI:
pip install scour
To install the latest trunk version (which might be broken!) from GitHub:
pip install https://github.com/codedread/scour/archive/master.zip
Usage
Standard:
scour -i input.svg -o output.svg
Better (for older versions of Internet Explorer):
scour -i input.svg -o output.svg --enable-viewboxing
Maximum scrubbing:
scour -i input.svg -o output.svg --enable-viewboxing --enable-id-stripping \
--enable-comment-stripping --shorten-ids --indent=none
Maximum scrubbing and a compressed SVGZ file:
scour -i input.svg -o output.svgz --enable-viewboxing --enable-id-stripping \
--enable-comment-stripping --shorten-ids --indent=none