Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer path conversion #1270

Open
ConsciousCode opened this issue Jul 25, 2020 · 1 comment
Open

Integer path conversion #1270

ConsciousCode opened this issue Jul 25, 2020 · 1 comment

Comments

@ConsciousCode
Copy link

ConsciousCode commented Jul 25, 2020

This is a suggestion for a plugin and request for issues which might arise.

SVG is most often used in a scalable context, so ultimately the actual units, width/height values, and scale don't matter. I'm proposing 2-3 passes: First, rescale everything in the SVG by the largest precision (this may make the file bigger if one outlier with high precision exists alongside lots of low-precision values, so something slightly less naive would be ideal, maybe find the median precision) such that all values are integers. Second, rescale the integer values again using GCD and rounding (eg gcd(100, 101) to gcd(100, 100)) until the rounding amount of any value is larger than a certain threshold in percent-changed. Third, further reduce by division by allowing the values to be real again (optional step since this won't usually have benefits)

This won't always produce a smaller file, but I think it'd be useful enough for certain cases. The purpose of this plugin would essentially be optimizing out the decimal points in paths and sizes and then reducing the lengths by fuzzy gcd to avoid degenerate cases like "21000".

Is there something I'm missing? Otherwise I could start working on it

@RodrigoRoaRodriguez
Copy link

RodrigoRoaRodriguez commented Nov 1, 2022

I have personally written scripts that do something very similar to this and I can attest that they work in reducing the size of SVG images. If done correctly removing the decimal dot is a lossless way of reducing svg file sizes, as the decimal point in every number contains no information and only bloats the markup.

Until this is implemented by someone, there exists a work-around if you want to do this without writing your own script. Just scale up the svg file to be at pixel resolution or higher and then optimize it with a zero precision, i.e:

svgo -p 0 filename

Last time I did this, it net me a 35.1% size reduction on the already svgo optimized image with zero pixel diff versus the previous image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants