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

Enable zopfli on oxipng #1413

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

Csabesz07
Copy link

This feature lets the user further optimise the compression of the image by adding new options under oxipng.

  • The deflater of oxipng is now selectable (zopfli / libdeflater)
  • Both deflater's parameters are modifiable (iterations / compress level)

| 'sync'
| 'async'
| 'auto'
| SignalLike<'sync' | 'async' | 'auto' | undefined>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be here? (it's causing the build to fail)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without that I get this error: Subsequent property declarations must have the same type. Property 'decoding' must be of type '"sync" | "async" | "auto" | SignalLike<"sync" | "async" | "auto" | undefined> | undefined', but here has type '"sync" | "async" | "auto" | undefined'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakearchibald After further investigation I found that the error was caused by a package version error. After fixing that, the error is gone, so the code you mentioned

@jakearchibald
Copy link
Collaborator

This is exciting!

@surma
Copy link
Collaborator

surma commented Apr 22, 2024

@Csabesz07 Your code seems to be working :) If you compress a bigger image, the time it take to compress is hugely different although in this case, the compressed file size is almost identical, which is not completely unexpected :D

Screenshot 2024-04-22 at 09 00 01

I’ll do a review in a bit :)

@@ -20,6 +24,23 @@ pub fn optimise(
} else {
Interlacing::None
});
match deflater {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to introduce a type here first, like we have in the resize module, so we can match on semantically meaningful words rather than numbers.

Also, invalid numbers should be panic()’d, not just use a default value.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @surma !

Is this what you were thinking of e3bb3a9 ?

}
1 => {
options.deflate = Deflaters::Zopfli {
iterations: Option::unwrap(NonZeroU8::new(iterations)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
iterations: Option::unwrap(NonZeroU8::new(iterations)),
iterations: NonZeroU8::new(iterations).unwrap(),

@jakearchibald
Copy link
Collaborator

jakearchibald commented Apr 22, 2024

the time it take to compress is hugely different although in this case, the compressed file size is almost identical, which is not completely unexpected :D

I'm not seeing any difference when changing the deflater, or the iterations / compress level setting, which feels a bit sus

@Csabesz07
Copy link
Author

I'm not seeing any difference when changing the deflater, or the iterations / compress level setting, which feels a bit sus

Exactly! This is my concern as well, but the way I see, all options are being applied at the moment.
Oxipng documentation mentions that if any of the optimize's options's properties are defined manually, the initial preset options will be overriden with those.

@surma
Copy link
Collaborator

surma commented Apr 22, 2024

I rebuilt the codec locally when testing. I wonder if the binaries on the PR are outdated or something. I’ll take another look tomorrow at that.

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

Successfully merging this pull request may close these issues.

None yet

3 participants