Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 31, 2025
1 parent 107e623 commit b851f0a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Drivers/Imagick/Modifiers/CropModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Intervention\Image\Drivers\Imagick\Modifiers;

use Imagick;
use ImagickPixel;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\CropModifier as GenericCropModifier;
Expand Down Expand Up @@ -45,16 +46,21 @@ public function apply(ImageInterface $image): ImageInterface
$canvas->setImageDispose($frame->native()->getImageDispose());
}

// Make the entire rectangle at the position of the original image
// transparent so that we can later place the original on top.
// This preserves the transparency of the original and shows
// the background color of the modifier in the other areas
$clear = new Imagick();
$clear->newImage($frame->native()->getImageWidth(), $frame->native()->getImageHeight(), 'black');
$canvas->compositeImage($clear, Imagick::COMPOSITE_DSTOUT, ...$position);
// make the rectangular position of the original image transparent
// so that we can later place the original on top. this preserves
// the transparency of the original and shows the background color
// of the modifier in the other areas. if the original image has no
// transparent area the rectangular transparency will be covered by
// the original.
$clearer = new Imagick();
$clearer->newImage(
$frame->native()->getImageWidth(),
$frame->native()->getImageHeight(),
new ImagickPixel('black'),
);
$canvas->compositeImage($clearer, Imagick::COMPOSITE_DSTOUT, ...$position);

// place original frame content onto the empty colored frame canvas
// with the transparent rectangle
// place original frame content onto prepared frame canvas
$canvas->compositeImage($frame->native(), Imagick::COMPOSITE_DEFAULT, ...$position);

// add newly built frame to container imagick
Expand Down

0 comments on commit b851f0a

Please sign in to comment.