Skip to content

Added is_lossless to WebPImageFile#9602

Open
ajslater wants to merge 5 commits intopython-pillow:mainfrom
ajslater:feature/webp-is-lossless
Open

Added is_lossless to WebPImageFile#9602
ajslater wants to merge 5 commits intopython-pillow:mainfrom
ajslater:feature/webp-is-lossless

Conversation

@ajslater
Copy link
Copy Markdown

@ajslater ajslater commented May 1, 2026

I find it useful to know if a WebP Image was encoded with the lossless bit set. While the exact amount of true 'losslessness' in encoded images can be a contentious subject, i find knowing the encoder's intent useful.

This sets the is_lossless property to true if every frame of the WebP was encoded with the lossless bit set. A simple determination for single frame images, but a restrictive judgement call for animated WebP's which main contain a mix of frame types.

Tell me if this looks useful and I can modify this PR to work well as a Pillow contribution.

@ajslater
Copy link
Copy Markdown
Author

ajslater commented May 1, 2026

There's possibly a general case for an "is_lossless" property on many or all Image formats.
png & gif would always be True. jpeg would always be False. It would be most useful on any other mixed types that require small algorithms like this one to determine.

@radarhere radarhere added the WebP label May 2, 2026
@radarhere
Copy link
Copy Markdown
Member

I find it useful to know if a WebP Image was encoded with the lossless bit set.

Could you elaborate on this?

If we did go with your suggestion, I think it would be better as another key in self.info, rather than a separate property.

Comment thread src/PIL/WebPImagePlugin.py Outdated
radarhere and others added 2 commits May 4, 2026 08:14
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@ajslater
Copy link
Copy Markdown
Author

ajslater commented May 5, 2026

I find it useful to know if a WebP Image was encoded with the lossless bit set.

My picopt program does lossless optimization. There isn't a way I know of to further compress a lossy WebP image without losing information, so I disqualify images from my program's optimizations by detecting if they were encoded as lossless or not.

Your preference for metadata going into the info dict makes sense. If it looks like we should proceed with this, I'll put the bit there.

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