hMatoba / Piexif

Exif manipulation with pure python script.
MIT License
369 stars 82 forks source link

Fix Animated WebP Support: Canvas Size Detection and Alpha Channel Handling #146

Open skidder opened 2 months ago

skidder commented 2 months ago

Description

This pull request addresses two key issues related to handling animated WebP files in the Piexif library:

  1. Canvas Size Detection:

    • Issue: https://github.com/hMatoba/Piexif/issues/145
    • Previously, the VP8X chunk dimensions were incorrectly set based on the last frame encountered, which could result in canvas dimensions being too small when frames of varying sizes were present.
    • The code has been updated to track the maximum width and height across all frames, ensuring that the VP8X chunk accurately reflects the overall canvas size.
  2. Alpha Channel Detection for Animated Frames:

    • Issue: https://github.com/hMatoba/Piexif/issues/144
    • The library failed to correctly detect and set the alpha flag in the VP8X chunk for animated WebP files where ALPH chunks were nested within ANMF chunks.
    • A new function, _get_sub_chunks_from_anmf, has been introduced to recursively examine sub-chunks within ANMF chunks while preventing excessive recursion through a depth limit.
    • This ensures that the alpha flag is properly set when transparency data is present in any frame of the animation.

Testing