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

floatPrecision should ignore gradient stops #1828

Open
tasiotas opened this issue Nov 9, 2023 · 3 comments
Open

floatPrecision should ignore gradient stops #1828

tasiotas opened this issue Nov 9, 2023 · 3 comments
Labels

Comments

@tasiotas
Copy link

tasiotas commented Nov 9, 2023

Hi,

I noticed that when setting floatPrecision to 0, it will totally mess up gradient stops.
It does work well on path/shapes position precision optimization, but not so well on gradient stops.

Perhaps we could have a flag to exclude or set separate floatPrecision for gradient stops?

before

<linearGradient id="a" x1="2" x2="139.4" y1="43.4" y2="-.9" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#fc0"/>
      <stop offset=".1" stop-color="#ff7600"/>
      <stop offset=".2" stop-color="#ff6d1e"/>
      <stop offset=".3" stop-color="#ff556c"/>
      <stop offset=".4" stop-color="#ff2fe6"/>
      <stop offset=".5" stop-color="#ff29f9"/>
      <stop offset=".6" stop-color="#ca36fb"/>
      <stop offset=".8" stop-color="#5e50fe"/>
      <stop offset=".9" stop-color="#335bff"/>
      <stop offset="1" stop-color="#237aff"/>
      <stop offset="1" stop-color="#217dff"/>
    </linearGradient>

after

<linearGradient id="a" x1="2" x2="139" y1="43" y2="-1" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#fc0"/>
      <stop offset="0" stop-color="#ff7600"/>
      <stop offset="0" stop-color="#ff6d1e"/>
      <stop offset="0" stop-color="#ff556c"/>
      <stop offset="0" stop-color="#ff2fe6"/>
      <stop offset="0" stop-color="#ff29f9"/>
      <stop offset="1" stop-color="#ca36fb"/>
      <stop offset="1" stop-color="#5e50fe"/>
      <stop offset="1" stop-color="#335bff"/>
      <stop offset="1" stop-color="#237aff"/>
      <stop offset="1" stop-color="#217dff"/>
    </linearGradient>
@tasiotas tasiotas added the bug label Nov 9, 2023
@GreLI
Copy link
Member

GreLI commented Nov 14, 2023

Not so sure that it should. E.g. you would want instead of something like 0.66667 to use .67. Zero digits is actually quite extreme setting, though it can have it uses.

@tasiotas
Copy link
Author

I was just comparing output from this library vs https://svgomg.net.

On svgomg I do get a benefit of of smaller filesize when setting precision to 0 and still having intact gradients.

@Paul-Browne
Copy link

Paul-Browne commented Nov 21, 2023

#1843

would solve your issue by passing

floatPrecision: {
    default: 0,
    offset: 2
}

Alternatively

floatPrecision: {
    d: 0,          // for paths, d="M123 456 789..."
    points: 0      // for polygons
}

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