Skip to content

Expose advanced WebP encoding options - #9936

Open
akx wants to merge 4 commits into
python-pillow:mainfrom
akx:webp-advanced-options-2
Open

Expose advanced WebP encoding options#9936
akx wants to merge 4 commits into
python-pillow:mainfrom
akx:webp-advanced-options-2

Conversation

@akx

@akx akx commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closes #1263 (supersedes it). It wasn't really possible to rebase neatly after more than a decade, so this is a rewrite + expansion; libwebp has grown more features since.

  • The minimum version of libwebp Pillow requires is bumped to 1.2.0, which has all of the options we expose. This should have no practical effect for any downstream that would be packaging Pillow 13 anyway, since that version was released back in 2021 already.
  • The internal API for passing options to the C WebP codec is now a dict, not a number of arbitrary arguments. (This mirrors, in a way, ImageText, Add ImageText #9098, though this is an internal (C interface is internal #9879, API.) The dict grew support for almost (see code comment) all WebP encode options.
  • While I was in there, the Pillow-to-libwebp copy, although a tiny part of the entire encode, was easy enough to optimize a bit.

None of the advanced options are required for successful WebP use, but "preset"s were not available, and those can be useful for more general use, so they're documented under "regular" options.

I also noticed that the documentation said the default method (encoding speed, more or less) was always 4; it had actually been 0 ever since animated WebPs were introduced in #2761. I didn't change the default, just the docs.

@radarhere radarhere added the WebP label Sep 1, 2026
akx added 4 commits September 1, 2026 18:02
It should be noted that libwebp 1.3.2 has patched vulnerabilities;
in practice, modern distributions will either have backported those
patches, or use a libwebp fresher than this.

But this is the ABI baseline.
It's a tiny piece of the whole encode, but this was easy enough to do.
On my machine, 2x to 3x for RGBA, 1.1x to 1.8x for RGB.
@akx
akx force-pushed the webp-advanced-options-2 branch from fa7cbce to 5ee0998 Compare September 1, 2026 15:04
@akx

akx commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

cc @Efreak, you had commented on #1263, and @ikait as the original author of #1263 if you want to take a look! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants