Skip to content

Commit

Permalink
Re-apply animation details
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 10, 2025
1 parent 9921ab8 commit d40fdd1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Drivers/Imagick/Modifiers/CropModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,32 @@ public function apply(ImageInterface $image): ImageInterface
$this->driver()->handleInput($this->background)
);

// create empty container imagick to rebuild core
$imagick = new Imagick();
$resolution = $image->resolution()->perInch();

foreach ($image as $frame) {
// create new frame canvas with modifiers background
$canvas = new Imagick();
$canvas->newImage($crop->width(), $crop->height(), $background, 'png');
$canvas->setImageResolution($resolution->x(), $resolution->y());

// set animation details
if ($image->isAnimated()) {
$canvas->setImageDelay($frame->native()->getImageDelay());
$canvas->setImageIterations($frame->native()->getImageIterations());
$canvas->setImageDispose($frame->native()->getImageDispose());
}

// place original frame content onto the empty colored frame canvas
$canvas->compositeImage(
$frame->native(),
Imagick::COMPOSITE_OVER,
($crop->pivot()->x() + $this->offset_x) * -1,
($crop->pivot()->y() + $this->offset_y) * -1,
);

// copy alpha channel if available
if ($frame->native()->getImageAlphaChannel()) {
$canvas->compositeImage(
$frame->native(),
Expand All @@ -42,9 +53,11 @@ public function apply(ImageInterface $image): ImageInterface
);
}

// add newly built frame to container imagick
$imagick->addImage($canvas);
}

// replace imagick
$image->core()->setNative($imagick);

return $image;
Expand Down

0 comments on commit d40fdd1

Please sign in to comment.