Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to flatten SVG nested transformations [closed]

I wonder if there is any command-line tool available to flatten nested groups with transformations in an SVG?

In my particular case, I am converting a CAD-software produced PDF to SVG and then adding some elements and publishing the modified SVG to a web page for viewing. The response time of the SVG is very sluggish (for panning and zooming) and I found that it is due to a very large number of nested groups inside the SVG, often up to several 100 depth. For each element in the SVG, the browser needs to calculate the position across all its parent nodes...

Obviously this is ridiculous, as all these elements need is one single transformation (matrix). So I wonder if anyone knows of a tool to flatten this (or a C# or Delphi implementation that would do so...).

like image 723
Optavius Avatar asked Oct 11 '12 10:10

Optavius


3 Answers

The best I have found is svgo https://github.com/svg/svgo But it is still not satisfactory. SVGO's goal is to produce a smaller svg file. That means if a transformation allows for a smaller svg file it is kept. My purposes is similar to OP's but slightly different. I am looking for something that can flatten out and completely simplify the SVG to just basic paths & elements.

like image 126
over_optimistic Avatar answered Nov 15 '22 15:11

over_optimistic


You may have a go with SVG Cleaner. It's unfortunately a GUI tool, so it does not really suit your requirements but it offers a batch processing philosophy that could turn useful.

like image 28
Delapouite Avatar answered Nov 15 '22 16:11

Delapouite


Thanks Delapouite,

meanwhile I found this one: (PStill). It does a perfect job of flattening the structure (PDF to PDF), but the resulting SVG still has a lot of elements in it making it quite unusable for a browser. It is really the trouble of what CAD systems produce to PDF: A lot of very small paths instead of one longer path. I'm pretty sure there is still room for optimization... one day :-)

like image 1
Optavius Avatar answered Nov 15 '22 15:11

Optavius