-
Notifications
You must be signed in to change notification settings - Fork 83
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
Incorrect VP8X Canvas Dimensions in Animated WebP Files #145
Comments
That isn't necessarily enough. Some webp files have a canvas that's larger than all frames. Here's a file where the canvas is 16x16 but the two animation frames are 12x10 and 8x2 respectively:
(This images was drawn by myself and saved using aseprite. Feel free to use it in tests, I hereby put it in the public domain.) |
@nico Thanks for the follow-up and that interesting test case! It's right to include examples of WebPs with canvases bigger than their frames - definitely adds another layer to think about. I've taken a good look at your test fix, and I think it's actually handling these cases pretty well for spec-compliant WebPs. Here's the gist:
For your 16x16 canvas example with smaller frames:
I've thrown a bunch of different WebPs at it, including some funky animated ones, and it seems to be handling them fine. Thanks again for diving into this! |
Summary
Piexif incorrectly sets the
VP8X
canvas dimensions for certain animated WebP files, leading to a "Frame exceeds canvas" error when frames exceed the dimensions of the last frame.Steps to Reproduce:
webpinfo
on the output file to observe the error.This can be reproduced with the
pil_animated2.webp
file in my fork: 5a12974Input Test File
Output Test File
Expected Behavior:
The
VP8X
chunk should reflect the maximum dimensions across all frames to correctly represent the entire canvas, preventing any "Frame exceeds canvas" errors.Actual Behavior:
The
VP8X
chunk dimensions are set based on the last frame processed. If this frame is smaller than earlier frames, the overall canvas size is incorrect, leading to errors.This issue affects users processing animated WebP files with frames of varying sizes. Ensuring the correct canvas size in the
VP8X
chunk is critical for maintaining compatibility and avoiding errors in tools that validate WebP file structure.Technical Details
The issue arises because the
set_vp8x
function in thepiexif
library sets the width and height based on the last frame it processes. This approach fails to account for previous frames that may be larger, resulting in an incorrect canvas size.WebP Image (OK)
For non-animated WebP files, the
VP8X
chunk correctly represents the image dimensions:Animated WebP (Broken)
For animated WebP files, the
VP8X
chunk incorrectly sets the canvas dimensions based on the last frame processed, even if earlier frames are larger:Proposal:
Modify the
set_vp8x
function to track the maximum width and height across all frames. TheVP8X
chunk should be updated to reflect these maximum dimensions, ensuring that the canvas size accommodates all frames.I have a commit in my fork that appears to resolve this: 7c6522a
The text was updated successfully, but these errors were encountered: