svgo
svgo copied to clipboard
Feature Req: Add Option to remove/flatten all clipPath and all mask elements
SVGs exported from Adobe Illustrator make often extensive use of clipPath and mask elements. Sometimes those clipped or masked elements are as big as the image even if the part displayed in the end is very small. Those are very slow because of multiple layers redraw and also tend to bloat the code. A clipPath applied on a closed curve or a polygon can be easily replaced by a single curve with a simple boolean operation.
In my tests with Inkscape I've found that an svg file with 5-6 layers of complex closed curves + clipPaths exported from Adobe Illustrator can be flattened with boolean operations and resulting in a single merged element made of closed paths with no loss of quality. Masks can be also transformed in flat shapes using alpha colors and bezier curves.
The result is identical to the original svg image, only flattened and with reduced overdraw.
Path merging and computation is a complex topic. Can you suggest an effective algorithm (i.e. better then O(n²))?
I have this problem as well when trying to optimize an SVG that has the world map in vector format, and only part of it is shown by masking... Any solutions for optimizing such SVG with Sketch or Illustrator (or other but those I mainly use)?
Update: Used this solutions before using this svg optimizer...got 1.6mb down to 770kt =§
Any update on this?
No update and unlikely there will be in the near future. I have no idea how to do this effectively. It's better to do such thinks in an image editor.
How about this: https://gist.github.com/timo22345/9413158 ?
Seems like it's just converting to shapes and applying transformations. Nothing to do with clip-paths.
https://github.com/w8r/martinez/ is a very good tool to compute intersections between polygons. Might be a good approach.
This would be a very nice feature. I work frequently with SVGs converted from other formats like DWG and these files also contain a lot of layers and invisible (clipped) paths. Removing/optimizing them would greatly reduce the file size.
A work in progress implementation of such clipping: https://github.com/ACTIVmap/svg-to-stl
Any news on this?
Any news on this? This appears to be a useful functionality for SVGO.
For anyone stuck on this, check out this StackOverflow answer: https://stackoverflow.com/a/70278985
I'd love to see this incorporated into svgo - looks like a pretty straightforward use of paper.js's intersect function.