-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add compression level #488
Conversation
fc7774e
to
697e160
Compare
Could you say a bit about why you want this functionality? One weird aspect of this PR is that Lines 696 to 697 in 2cfde02
Another complication is that |
Apologies for the short PR description it was a bit late for me when I opened it.
I'm building a Wasm package for compressing PNG, mostly canvas-generated PNG images which lack compression. And for my specific case, QR Images, Also wanted to give users a more familiar compression setting, most libs (libvips, ImageMagick) I've used for handling images usually have a PNG compression level between 0-9
I'm currently building it myself with this patch applied, but thought that others may need this feature as well. So in my specific case I don't mind waiting for the next breaking release. |
I also need this for the drop-in replacement for |
Could we instead add this as a new method on the encoder, like |
I would also like this option, since the "Best" compression level in this crate, according to it's docs, does not actually use maximum compression, and there are no other variants that are higher either: /// Higher compression level
///
/// Best in this context isn't actually the highest possible level
/// the encoder can do, but is meant to emulate the `Best` setting in the `Flate2`
/// library.
Best, |
Given that |
The documentation on As far as the overall API design, I've held off responding because I didn't see any elegant way to design this API that wouldn't be confusing / risk making future changes harder:
|
It's too detailed, and backend-specific. We could add another preset if you really need something in between the existing ones. |
I'm still going to need detailed compression presets for And I do believe optionally giving more control over the compression levels to the API user is ultimately a good thing, as long as it is an "advanced" API that users are not required to familiarize themselves with for basic usage. |
The compression settings in imagemagick are deeply tied to zlib / libpng's capabilities. Notably in addition to the 0-9 levels, they also include I do think it is worth adding at least one compression level between |
I am tempted to add an "advanced compression setting" enum in roughly this shape: #[non_exhaustive]
pub enum AdvancedCompressionSettings {
/// Extremely fast but light compression
Fdeflate(FdeflateSettings),
/// Regular compression
Flate2(u8),
} Then we could easily add But this raises questions on how this would be exposed in We don't want to couple The only question is, what do we do about fdeflate's mode that doesn't use a fixed dictionary? I want to benchmark it against miniz_oxide and zlib-rs, but I don't think it's exposed in any way right now? Is there a way I can actually get to it through the |
It hasn't been written yet... so it's a bit early for that sort of benchmarking 😄 |
This PR adds
Compression::Level(u32)
to allow finer control over compression settings. It maps directly toflate2::Compression::new(level)
.