svg / svgo

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

most content missing from large svg #890

Closed jirilebl closed 3 years ago

jirilebl commented 6 years ago

Running svgo on http://www.jirka.org/nlin-sierpinski-mbx.svg kills everything in the picture.

jirilebl commented 6 years ago

It is the convertPathData plugin. If I disable that, things work, and the svg gets very nicely minimized (with multipass) to 472kb

XhmikosR commented 3 years ago

I cannot reproduce with svgo 2.0.2, although it's slow. @TrySound maybe this is also fixed?

C:\Users\xmr\Desktop>svgo -i 22.svg -o 23.svg

22.svg:
Done in 142022 ms!
2594.036 KiB - 92.3% = 199.252 KiB
TrySound commented 3 years ago

Thanks. Looks like all works. I will look into performance later.

jirilebl commented 3 years ago

I was excited to hear that it is fixed. However,, I just tried it with newly installed svgo version 2.1.0 and it still totally kills the picture, I get a mostly empty picture:

➤ svgo -i nlin-sierpinski-mbx.svg -o test.svg

nlin-sierpinski-mbx.svg: Done in 24112 ms! 2583.887 KiB - 99.5% = 13.275 KiB

Not sure what other difference for me. I'm running on linux, Ubuntu 20.10 to be precise. Installed through npm.

XhmikosR commented 3 years ago

Hmm, this broke again in 2.1.0 it seems @TrySound

Microsoft Windows [Version 10.0.19042.844]
(c) 2020 Microsoft Corporation. All rights reserved.

C:\Users\xmr\Desktop>node -v
v14.15.5

C:\Users\xmr\Desktop>curl -sL http://www.jirka.org/nlin-sierpinski-mbx.svg>1.svg

C:\Users\xmr\Desktop>svgo 1.svg -o 2.svg

1.svg:
Done in 38192 ms!
2583.887 KiB - 99.5% = 13.275 KiB

C:\Users\xmr\Desktop>npm i -g svgo@2.0.2
C:\Users\xmr\AppData\Roaming\npm\svgo -> C:\Users\xmr\AppData\Roaming\npm\node_modules\svgo\bin\svgo
+ svgo@2.0.2
added 1 package from 1 contributor, removed 1 package and updated 1 package in 2.9s

C:\Users\xmr\Desktop>svgo 1.svg -o 2.svg

1.svg:
Done in 145807 ms!
2583.887 KiB - 92.3% = 199.252 KiB

Better reopen the issue and add this SVG to the tests

EDIT:

Output diff between 2.0.2 and 2.1.0:

Diff ```diff diff --git "a/C:\\Users\\xmr\\Desktop\\2.svg" "b/C:\\Users\\xmr\\Desktop\\3.svg" index 44ef99b..d3a2c6b 100644 --- "a/C:\\Users\\xmr\\Desktop\\2.svg" +++ "b/C:\\Users\\xmr\\Desktop\\3.svg" @@ -34,137 +34,173 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ```
XhmikosR commented 3 years ago

Correction, 2.0.3 also works fine. So, it seems it's something in https://github.com/svg/svgo/compare/v2.0.3...v2.1.0

EDIT: @TrySound it seems that enabling the convertStyleToAttrs plugin fixes the issue here :S

TrySound commented 3 years ago

Heh, interesting

TrySound commented 3 years ago

It's not easy to fix this permanently without new style engine which would be able to compute attributes and all styles. Though yeah enabling convertStyleToAttrs in your case would fix the issue.

jirilebl commented 3 years ago

Tested to try with convertStyleToAttrs, though it took me quite a while to figure out how to do that since --enable/--disable seem to be gone from cli and if I use the snippet for config to use the extendDefaultPlugins doesn't seem to work for me: I get "Error: Cannot find module 'svgo'". Finally, just stuck the full module list from the readme in there, and added 'convertStyleToAttrs' to the module list (added it at the end), and was still not getting it to work. Still got the mostly empty output.

Got it to work by sticking convertStyleToAttrs just in front of the convertPathData plugin. But I get a slightly different size so I am assuming I still have not figured out how to simply enable the plugin, and I must have disabled something else or not the right order.

➤ svgo -i nlin-sierpinski-mbx.svg -o test.svg

nlin-sierpinski-mbx.svg: Done in 197581 ms! 2583.887 KiB - 92.2% = 200.956 KiB

TrySound commented 3 years ago

To extend default plugins you need to install svgo locally. I guess we can do better. Will think about it.

TrySound commented 3 years ago

Fixed the image here https://github.com/svg/svgo/commit/79dbb4bf6e7464e946d838ade0aa23c7189762f7 ad here https://github.com/svg/svgo/commit/7901588a9f18d6ef476389405a73cd7fe42ed179. Will release today or tomorrow.

TrySound commented 3 years ago

Fixed in 2.2.0