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

PNG quality loss no matter the config with more examples #180

Closed
ysabri opened this issue Feb 23, 2023 · 3 comments
Closed

PNG quality loss no matter the config with more examples #180

ysabri opened this issue Feb 23, 2023 · 3 comments

Comments

@ysabri
Copy link

ysabri commented Feb 23, 2023

Sorry I'm opening #172 again, we've heard this complaint from multiple users.

I will give another example here where its more apparent.

The original image (1.74MB):
Cario_headshot

Compressed PNG (173KB):
Carioheadshot-rn5vhl

Compressed as a JPEG with the same config (221KB):
Carioheadshot-rn5vg5

Both these were with the same config I specified in #172 and is still the case with this image no matter what configs I try. There is always visible loss in quality.

I don't know what to do here, thanks for pointing out that we lose transparent backgrounds in the hack I used in #172, it is something we care about and this issue is preventing us from having.

@Donaldcwl
Copy link
Owner

Donaldcwl commented Mar 4, 2023

I have noticed that the compression strategy is a bit aggressive, with which the output is 173KB while your config maxSizeMB is 400KB. In the next release, I will increase the initial color depth during compression. So your current config will result in a better larger output image(<400KB).

However, PNG is lossless by design, so the approach in this library to compress PNG images is to reduce the color depth (number of different colors).
Since your config restricts the maxSizeMB to 0.4MB, which is quite small, there may not be enough colors to paint your image. You may decide to increase the maxSizeMB or reduce the maxWidthOrHeight or remind the same after the next release.

This was referenced Mar 5, 2023
@Donaldcwl
Copy link
Owner

Donaldcwl commented Mar 5, 2023

@ysabri v2.0.1 has been released. You can have a try.

@ysabri
Copy link
Author

ysabri commented Mar 6, 2023

@Donaldcwl Thank you for the quick turn around.

I just tested the change and it seems to be working fine!

Since I have you here, I wanted to ask about the maxIteration, I had set to 150 which made this change feel slow so I removed it and everything still seems to be working fine with the default 10. What should I worry about when it comes to the number?

@ysabri ysabri closed this as completed Apr 20, 2023
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