Scour - an SVG scrubber
« Back to Scour Main Page
Operations
Currently scour automatically performs the following operations on input SVG files:
- Removes unreferenced elements in a <defs>
- Removes all inkscape, sodipodi, adobe elements
- Removes all inkscape, sodipodi, adobe attributes
- Remove all unused namespace declarations on the document element
- Removes any empty <defs>, <metadata>, or <g> elements
- Style fix-ups:
- Fixes any style properties like this:
style="fill: url(#linearGradient1000) rgb(0, 0, 0);"
- Removes any style property of:
opacity: 1;
- Removes any stroke properties when stroke=none or stroke-opacity=0 or stroke-width=0
- Removes any fill properties when fill=none or fill-opacity=0
- Removes all fill/stroke properties when opacity=0
- Removes any text/font properties on shape elements
- Removes Inkscape-specific properties: -inkscape-font-specification
- Removes any
stroke: none
- Removes any
stop-opacity: 1
- Removes any
fill-opacity: 1
- Removes any
stroke-opacity: 1
- Remove any
display:none
- Remove any
visibility:visible
- Remove any
overflow:visible
- Remove any
marker:none
- Fixes any style properties like this:
- Convert style properties into SVG attributes
- Prevent error when stroke-width property value has a unit
- Convert width/height into a viewBox where possible
- Convert all referenced rasters into base64 encoded URLs if the files can be found
- prevent metadata from being removed if they contain only text nodes
- Remove unreferenced pattern and gradient elements outside of defs
- Removal of extra whitespace, pretty printing of XML
- Remove unnecessary nested <g> elements (as long as they have no attributes or title/desc children)
- Remove duplicate gradient stops (same offset, stop-color, stop-opacity)
- Convert gradient stop offsets into float/int
- Always keep fonts inside <defs>, always keep ids on fonts
- Collapse any gradient that is only referenced by one other gradient
- Convert all colors to #RRGGBB format
- Reduce Path Data:
- Remove unnecessary whitespace between commands, negative coordinate
- Limit to 5 digits of precision, this can be modified with the --set-precision argument
- Converts absolute to relative path commands
- Remove empty line and curve segments
- Convert lines to horiz/vertical line segments where possible
- Convert curvest to shorthand equivalents where possible
- Collapse consecutive h,v segments/coordinates where possible
- Collapse adjacent commands of the same type
- Convert straight curves into line commands
- Remove trailing zeros after decimals
- Use scientific notation if that representation is shorter
- Remove last coordinate from polygon if possible
- Reduce polygon points data as per path data reduction
- Reduce polyline points data as per path data reduction
- Scour length/coordinate attributes (integerize, remove trailing zeros, etc)
- Remove redundant SVG namespace declarations and prefixes
- Move common attributes to ancestor elements