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

Plugin 'convertTransform' corrupts image #1810

Open
phpcoder2022 opened this issue Oct 19, 2023 · 4 comments
Open

Plugin 'convertTransform' corrupts image #1810

phpcoder2022 opened this issue Oct 19, 2023 · 4 comments
Labels

Comments

@phpcoder2022
Copy link

Step to reproduce:

  1. Clone repo from my bug test project
  2. Go to repo directory
  3. npm i
  4. npm run build
  5. Run serve in dist directory
  6. Visit server page
  7. See that image was showed correctly
  8. Stop serve
  9. Delete value in excludedSvgoPluginsBecauseItCorruptImages in webpack.config.js
  10. npm run build
  11. Run serve in dist directory
  12. Visit server page
  13. See that image was corrupted

Actual result:

Image was corrupted

Expected result:

Image on second view must be equal image on first view

Svgo version: ^3.0.2
NodeJS version: v18.13.0
OS version: Ubuntu 23.04 Lunar Lobster

@SethFalco
Copy link
Member

The problem is ultimately rounding. The convertTransform plugin reduces the number of decimal places, which changes in output to -.125 to -.13.

We make the assumption that there's no need to add more precision than there already is. So since it started with 2 decimal places, we assume that we can round to two decimal places at the end.

We should make this do one of the following:

  • Use significant digits instead of decimal places to determine floating-point precision.
  • Take the existing number of decimal places + 1 to calculate the desired precision, the plus 1 offset being what we consider a non-negligible change.
  • Drop that logic altogether.

There may be edge cases where this still screws up the SVG, but this should certainly improve the situation for now.

@phpcoder2022
Copy link
Author

I created additional branch overrides, where I overrided svgo plugins options. Three commits was placed on this branch and in any ones webpack.config.js have different settings. I discover that disabling of option collapseIntoOne solved this problem, but increasing of ...Precision settings do not.

Thus enabling of plugin convertTransform have some risk. Will you may descript it in documentation at least short?

@SethFalco
Copy link
Member

I'd actually consider this a bug based on my findings above. Rather than update the documentation, I intend to resolve the precision issue.

You're correct, updating the precision settings wouldn't help due to the assumptions that are made. For some reason, that takes precedence over the parameters, which I'd also consider a bug tbh. 🤔

@charlyoleg2
Copy link

I also get a corrupted image when using 'convertTransform'. I upload my files here to give you an other example of corruption:

  • abc_original.svg
  • abc_svgo_optimized_with_convertTransform.svg (corrupted! path30 is shifted on the left outside the document)
  • abc_svgo_optimized_without_convertTransform.svg (not corrupted)
  • svgo.config.cjs
    Using
  • node v20.10.0
  • svgo 3.0.4
  • ubuntu 22.04
    abc_svgo_optimized_without_convertTransform
    abc_svgo_optimized_with_convertTransform
    abc_original
    svgo.config.cjs.txt

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

No branches or pull requests

3 participants