Command line tool to resolve transforms in SVG

Is there any commandline tool that can remove transforms from an SVG file (or rather apply the transforms), translating all coordinates to stay in place?

This is one of the thing that none of the most well-known SVG cleaning tools (svgo, svgcleaner, etc) handles, as far as I understand.

In other words, I would like to go from something like this:

<g
   transform="matrix(0.9,0,0,0.99,650,280)"
>
  <path
     d="M591,1037 L589,1044 ...
  >
</g>

to something like this

<g>
  <path
     d="M204,503 L321,403 ...
  >
</g>

…or from something like this:

<path
   transform="matrix(0.9,0,0,0.99,650,280)"
   d="M591,1037 L589,1044 ...
>

to something like this

<path
   d="M204,503 L321,403 ...
>

Links

For reference, there is an old, unmaintained Inkscape extension that does this: Apply Transforms)

Stack Overflow question, with tips on how to do this in Inkscape (through the GUI), including a note that this used to be possible with svgo: Removing transforms in SVG files

Open ticket at the svgo repo: Please add the option to flatten transforms #624

Asked By: leo

||

SVGO works fine for your example. I tested on 3.2.0. npm i -g svgo and svgo in1.svg in2.svg -o out1.svg out2.svg:

in1.svg

<svg  rel="nofollow noreferrer">removing transforms is enabled by default.

Keep an eye on the recent pull requests, and update when there are new releases. There are some small bugs that will be fixed soon. Shapes will be supported but the question talks about paths.

Answered By: Daniel T
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.