Alex Rivera | Logout

apply all transform matrices

Asked 2012-04-12T15:14:00.880
8

I am looking for a possibly fast way to apply all transform matrices of a given svg-graphic. In other words: the algorithm should remove all "transform" attributes and transform all coordinates of the graphic to absolute coordinates.

Is their any library that can do this, or is their any SVGDomInterface method that coulld do that?

EDIT::

If I call the consolidate method like this:

$.each( svg.find( 'path' ), function( i ){
        this.transform.baseVal.consolidate();
});

nothing happens, if i call it like this:

$.each( svg.find( 'path' ), function( i ){
        this.transform.animVal.consolidate();
});

i get this error:

error

So, how should i use the "consolidate" method, on which elements shall I call it?

Greetings philipp

Edit
Report

1 Answer

6

SVG Cleaner didn't seem to apply all transforms for me, but Inkscape does. Here's the command line I use when I need to apply one:

inkscape copy-of-file.svg --select=id-of-node \
         --verb=EditCut --verb=EditPaste \
         --verb=FileSave --verb=FileClose

Assuming you have "Transforms -> Store transformation" set to "Optimized" in inkscape's prefs (I believe it is on by default), this will apply it and produce the wanted result. Be sure you operate on a copy of your input file, as the operation replaces your original file!

If you are running this on a mac, you may want to first do this in your shell:

alias inkscape=/Applications/Inkscape.app/Contents/Resources/bin/inkscape
answered 2012-06-08T00:44:02.373

Your Answer