RazrFalcon / svgcleaner

svgcleaner could help you to clean up your SVG files from the unnecessary data.
GNU General Public License v2.0
1.62k stars 93 forks source link

Apply transform #213

Open doublex opened 4 years ago

doublex commented 4 years ago

Is there a chance to multiply the matrix to the path?

svgcleaner al.svg al.svg --apply-transform-to-paths=yes
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 512 512">
  <path fill="#e41e20" d="M0 0h512v512H0z"/>
  <path id="a" d="M204.9 99.5c-5 0-13.2 1.6-13 5.4-14-2.3-15.4 3.4-14.6 8.5 1.4-2 3-3.1 4.2-3.3 1.9-.3 3.8.3 5.8 1.5a23 23 0 015 4.4c-4.8 1.1-8.6.4-12.4-.3a17.6 17.6 0 01-6.1-2.5c-1.6-1.1-2.1-2.1-4.6-4.7-2.9-3-6-2.1-5 2.5 2.2 4.3 6 6.3 10.7 7 2.2.4 5.6 1.2 9.4 1.2 3.8 0 8.1-.5 10.5 0-1.4.8-3 2.4-6.2 3-3.2.6-8-2-11-2.6.4 2.5 3.5 4.8 9.7 6 10.2 2.2 18.7 4 24.3 7 5.6 3 9.1 6.8 11.6 9.8 5 6 5.3 10.5 5.6 11.5 1 9.5-2.2 14.8-8.4 16.4-3 .8-8.5-.7-10.5-3-2-2.4-4-6.4-3.4-12.7.5-2.5 3.4-9 1-10.3a291.6 291.6 0 00-34.4-16c-2.7-1.1-5 2.5-5.8 4A53.5 53.5 0 01129 107c-4.6-8.1-12.1 0-10.9 7.7 2.1 8.6 8.6 14.8 16.5 19.2 8 4.5 18.1 8.8 28.3 8.6 5.5 1 5.5 8.2-1.1 9.5-13 0-23.2-.2-32.9-9.6-7.4-6.7-11.5 1.3-9.4 5.8 3.6 14 23.6 18 43.8 13.4 7.8-1.3 3.1 7 .9 7.2-8.4 6-23.5 12-36.8-.1-6.1-4.7-10.2-.7-8 6 6 17.5 28.5 13.8 44 5.2 4-2.2 7.6 3 2.7 6.9-19.2 13.4-28.9 13.6-37.6 8.4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0 0013.7 2.3c3.3-.6 7-4.8 9.8-7 3-3.6 8.1.6 4.7 4.7-6.3 7.5-12.6 12.4-20.3 12.3-8.2 1-6.7 5.7-1.3 7.9 9.8 4 18.6-3.5 23-8.5 3.5-3.7 6-3.9 5.3 2-3.4 10.5-8.1 14.6-15.7 15.1-6.2-.5-6.3 4.2-1.7 7.5 10.3 7 17.7-5 21.2-12.4 2.5-6.6 6.3-3.5 6.7 2 0 7.3-3.2 13.2-12 20.7 6.7 10.7 14.5 21.7 21.3 32.5l20.5-228.2-20.5-36c-2.1-2-9.3-10.5-11.2-11.7-.7-.7-1.1-1.2-.1-1.6 1-.4 3.2-.8 4.8-1-4.4-4.4-8-5.8-16.3-8.2 2-.8 4-.3 9.9-.6a32.3 32.3 0 00-14.4-11c4.5-3 5.3-3.3 9.8-7-7.7-.6-14.3-2-20.8-4a41 41 0 00-12.8-3.7zm.7 9c4 0 6.6 1.4 6.6 3 0 1.7-2.5 3.1-6.6 3.1-4 0-6.6-1.5-6.6-3.2 0-1.7 2.6-3 6.6-3z"/>  
</svg>
JoKalliauer commented 4 years ago

@doublex :

You could

An even Better solution Actually in this case you could just replace the last path with <use transform="matrix(-1,0,0,1,512,0)" width="100%" height="100%" xlink:href="#a"/>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
 <path d="m0 0h512v512h-512z" fill="#e41e20"/>
 <path id="a" d="m204.9 99.5c-5 0-13.2 1.6-13 5.4-14-2.3-15.4 3.4-14.6 8.5 1.4-2 3-3.1 4.2-3.3 1.9-.3 3.8.3 5.8 1.5a23 23 0 0 1 5 4.4c-4.8 1.1-8.6.4-12.4-.3a17.6 17.6 0 0 1 -6.1-2.5c-1.6-1.1-2.1-2.1-4.6-4.7-2.9-3-6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4-20.3 12.3-8.2 1-6.7 5.7-1.3 7.9 9.8 4 18.6-3.5 23-8.5 3.5-3.7 6-3.9 5.3 2-3.4 10.5-8.1 14.6-15.7 15.1-6.2-.5-6.3 4.2-1.7 7.5 10.3 7 17.7-5 21.2-12.4 2.5-6.6 6.3-3.5 6.7 2 0 7.3-3.2 13.2-12 20.7 6.7 10.7 14.5 21.7 21.3 32.5l20.5-228.2-20.5-36c-2.1-2-9.3-10.5-11.2-11.7-.7-.7-1.1-1.2-.1-1.6s3.2-.8 4.8-1c-4.4-4.4-8-5.8-16.3-8.2 2-.8 4-.3 9.9-.6a32.3 32.3 0 0 0 -14.4-11c4.5-3 5.3-3.3 9.8-7-7.7-.6-14.3-2-20.8-4a41 41 0 0 0 -12.8-3.7zm.7 9c4 0 6.6 1.4 6.6 3 0 1.7-2.5 3.1-6.6 3.1-4 0-6.6-1.5-6.6-3.2s2.6-3 6.6-3z"/>
 <use height="100%" transform="matrix(-1 0 0 1 512 0)" width="100%" xlink:href="#a"/>
</svg>

use_use.svg.txt

@RazrFalcon Sorry for suggestion other software in your project, but I recommended svgcleaner very often on other projects.

leeoniya commented 4 years ago

+1 for flattening transforms. a lot of svg editors leave them in - sometimes many nested layers of them.

RazrFalcon commented 4 years ago

In most cases you cannot do this (due to referenced paint servers) or it will make the file bigger. So the current algorithm is working correctly. The problem is that it's mostly useless.

@JoKalliauer I don't mind, especially since svgcleaner is dead for now.

leeoniya commented 4 years ago

especially since svgcleaner is dead for now

that's too bad :(

i haven't found any better alternatives. any recommendations? i've used svgo, and like that i can reduce numeric precision, but i know that's antithetical to this project. either way, i think svgcleaner is better and faster at structural simplification than svgo (which this issue touches on).

RazrFalcon commented 4 years ago

any recommendations?

Only time. Eventually I will find the time to rewrite it.

JoKalliauer commented 4 years ago

@lencioni : As long as SVG1.1 is the golden standard not developed svg-optimizers don't get outdated (that fast).

At https://commons.wikimedia.org/wiki/User:JoKalliauer/Optimization#Using_Optizatiors I discuss several optimizers. The three comon comand-line svg-optimizers/cleaners/scubbers are svgcleaner,svgo,scour but none of them is developed actively any more see https://commons.wikimedia.org/wiki/Help:SVG#Tidying_up for references (Refs [16,17,18]).

Only time. Eventually I will find the time to rewrite it.

If you do not want to wait, I see three more soulutions

  1. You could donate to inkscape (for scour) or to svgo or hire RazrFalcon (for svgcleaner). (I would guess if you donate ~10€/hour it will be implemented quite fast.)
  2. You code it yourself and make a pull-request. (That's maybe the most expensive option, since time is imho expensive.)
  3. You hire someone else to make a pull-request. ( I would guess you have to pay ~70€/hour (for an unexperienced austrian developer). )