Is there a command-line tool to remove most "g transform..."s from my SVG files, so I can see the "absolute" location of my points/lines/polygons?
In other words, has anyone implemented the matrix multiplication technique explained in: Flattening SVG matrix transforms in Inkscape and How to get the actual x/y position of an element in SVG with transformations and matrices as a command-line tool?
SVG Cleaner appears to require Qt and does not appear to be a command-line tool (plus, I couldn't get it to compile)
No, nobody has made this tool. At least, not that either you or I can find. Part of the problem is in your definition. You ask to remove the transforms,
For a subset of SVG elements and transforms it is possible to bake the transform into the element's attributes, but it can't work in the general case. For example, consider this simple case:
There is no possible way to modify the
<rect>
element's specific attributes so that it shows the same result. The best you can do is to put atransform="…"
attribute on the<rect>
element representing the total global transforms. This is relatively easy to do in an SVG UA, slightly harder to do in a standalone command-line tool (but still possible). I would help you do it, but I figure the results don't help you, as they don't tell you anything about the absolute location of the points.You might be tempted to say "No, I can't do it with a
<rect>
, but I could convert the<rect>
into a<polygon>
or a<path>
and use absolute coordinates for those points." But you'd only be half correct. If you notice the varying apparent stroke width due to the skew, you will see that no single<polygon>
can accurately represent the skewed<rect>
.In general, the only thing you can do is bake the sum of all
<g>
transforms onto the individual elements, and realize that such transforms may drastically affect the final location and appearance of the content.