Skip to content

Added is_lossless to WebPImageFile#9602

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

Added is_lossless to WebPImageFile#9602
ajslater wants to merge 3 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.

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":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
if len(data) < 16 or data[:4] != b"RIFF" or data[8:12] != b"WEBP":
if not _accept(data):

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