Skip to content

Commit b851f0a

Browse files
committed
Refactor code
1 parent 107e623 commit b851f0a

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/Drivers/Imagick/Modifiers/CropModifier.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Intervention\Image\Drivers\Imagick\Modifiers;
66

77
use Imagick;
8+
use ImagickPixel;
89
use Intervention\Image\Interfaces\ImageInterface;
910
use Intervention\Image\Interfaces\SpecializedInterface;
1011
use Intervention\Image\Modifiers\CropModifier as GenericCropModifier;
@@ -45,16 +46,21 @@ public function apply(ImageInterface $image): ImageInterface
4546
$canvas->setImageDispose($frame->native()->getImageDispose());
4647
}
4748

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

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

6066
// add newly built frame to container imagick

0 commit comments

Comments
 (0)