svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
21.04k stars 1.39k forks source link

Remove default values like stroke-dasharray="none" stroke-opacity="1" #1973

Open atom3001 opened 7 months ago

atom3001 commented 7 months ago

Hi, I'm using SVGOMG, which is great, but can't remove wadding like default path values. Eg stroke-dasharray="none" stroke-opacity="1"

KTibow commented 7 months ago

Tip: SVGOMG hasn't been updated for a while, and won't be updated until #1943 is merged. https://omfg.svg.beauty/ is slightly more up to date, but it's best to directly use the library/CLI if you can.

Commentary on the issue: This is already done to some degree, but I wouldn't be surprised if it doesn't work in all cases. Want to share an example SVG where it should remove it but doesn't?

atom3001 commented 7 months ago

Thanks for the quick response @KTibow. Am running omfg via CLI now. Which does remove raster images properly, which is nice. I suppose I need to develop a plugin to add this feature but am pretty green so will be a struggle. Will paste an image with stuff I'd like to clean out. EG Defaults like: stroke-dasharray="none" stroke-opacity="1"

Styles to attributes gets rid of the above defaults on the last path but misses the initial two. Any help greatly appreciated

RR_v1_trim_1 RR_v1_trim_1_svgofm_1

KTibow commented 7 months ago

It seems the optimization is disabled when the path is linked in a use. I haven't found where this optimization is applied yet so I don't have much to add.

atom3001 commented 7 months ago

Yes, if I drop the use elements the path styles get cleaned properly. good spot, thanks. So I could cleanup before cloning. Shame to have a fragmented workflow. But writing plug-ins to do a second cleaning pass is beyond me for now. Thanks again for looking

KTibow commented 7 months ago

I checked and the relevant plugin is removeUnknownsAndDefaults, which actually doesn't clean defaults on attributes with an id

atom3001 commented 7 months ago

Interesting, thanks for digging deeper @KTibow. Still leaves me in the same boat. Perhaps it would be possible to disable that id limitation?