Added is_lossless to WebPImageFile#9602
Open
ajslater wants to merge 3 commits intopython-pillow:mainfrom
Open
Conversation
Author
|
There's possibly a general case for an "is_lossless" property on many or all Image formats. |
Member
Could you elaborate on this? If we did go with your suggestion, I think it would be better as another key in |
radarhere
reviewed
May 2, 2026
| def _is_lossless(data: bytes) -> bool: | ||
| # A WebP file is considered lossless when every coded frame uses the | ||
| # VP8L bitstream. See https://developers.google.com/speed/webp/docs/riff_container | ||
| if len(data) < 16 or data[:4] != b"RIFF" or data[8:12] != b"WEBP": |
Member
There was a problem hiding this comment.
Suggested change
| if len(data) < 16 or data[:4] != b"RIFF" or data[8:12] != b"WEBP": | |
| if not _accept(data): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.