Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Drivers/Imagick/Modifiers/RotateModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function apply(ImageInterface $image): ImageInterface
'Failed to apply ' . self::class . ', unable to rotate image',
);
}

// Reset the virtual canvas page that rotateImage() leaves behind. A
// non-right angle produces a negative page offset which otherwise
// corrupts the animated-AVIF (libheif sequences) writer, leaving the
// bottom/right region transparent. Mirrors TrimModifier/CoverModifier.
$frame->native()->setImagePage(0, 0, 0, 0);
} catch (ImagickException $e) {
throw new ModifierException(
'Failed to apply ' . self::class . ', unable to rotate image',
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/Drivers/Imagick/Modifiers/RotateModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,19 @@ public function testRotate(): void
$this->assertEquals(240, $image->width());
$this->assertEquals(320, $image->height());
}

public function testRotateResetsFramePageOffset(): void
{
// A non-right-angle rotation grows the virtual canvas; ImageMagick leaves
// each frame with a negative page offset. That offset mis-composes the
// animated-AVIF (libheif sequences) writer, leaving the bottom/right
// transparent, so rotate must reset every frame's page to +0+0.
$image = $this->readTestImage('animation.gif');
$image->modify(new RotateModifier(45, 'fff'));

foreach ($image as $frame) {
$this->assertSame(0, $frame->offsetLeft());
$this->assertSame(0, $frame->offsetTop());
}
}
}