Reset page geometry after Imagick rotation#1505
Merged
olivervogel merged 1 commit intoJul 7, 2026
Merged
Conversation
Imagick's rotateImage() grows the virtual canvas for non-right angles and leaves each frame with a negative page offset (a 480x480 frame rotated 45 degrees ends up 680x680-100-100). ImageMagick's animated-AVIF writer (libheif sequences) honours that offset when compositing the sequence, shifting every frame up and left and leaving the bottom/right region transparent. Reset each frame's page to +0+0 after rotating, mirroring TrimModifier and CoverModifier which already normalize page geometry. This keeps the Imagick driver consistent with the GD and vips drivers, which leave no offset, and fixes the transparent-corner artifact in animated AVIF.
Member
|
Thank you. |
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.
Rotating an image with the Imagick driver leaves a page offset on every frame. You don't notice it on a still image. On an animated one that then gets encoded to AVIF, it breaks: the bottom-right of every frame comes out transparent.
Where it comes from:
rotateImage()at a non-right angle grows the canvas and sets a negative page offset. A 480x480 frame rotated 45 degrees ends up with page680x680-100-100. The single-frame AVIF encoder and the animated WebP encoder ignore that offset. The animated AVIF path does not, it composites every frame shifted up and to the left.The real bug is in ImageMagick's animated AVIF writer, not in Intervention. But we can shield against it here, and the other modifiers already do this (see the fix below).
Repro with plain magick, no PHP involved:
Same thing through the library:
Fix: reset each frame's page to +0+0 right after
rotateImage().TrimModifierandCoverModifieralready do this after they change the canvas, so the rotate modifier is just catching up with them. GD and vips don't leave an offset after a rotate, so this also lines the drivers up.One line in
Drivers/Imagick/Modifiers/RotateModifier.php:Test: I added
testRotateResetsFramePageOffsetnext to the existing rotate test. It rotates an animated fixture by 45 and checks every frame has offset 0. It fails before the change and passes after.Corner pixel, same input, before and after:
Two things if you want to reproduce it:
It only shows with real photo-like frames. A flat color or a tiny synthetic gif compresses to trivial tiles and the corner stays fine, so use a real animated image.
You need an ImageMagick build with animated AVIF support. I saw it on 7.1.2-26, and it was also reported on a couple of earlier 7.1.2 builds. Older ImageMagick without animated AVIF is not affected.