Skip to content

Commit

Permalink
Refactor driver version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 11, 2025
1 parent c3f09eb commit cc0b332
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 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 Intervention\Image\Drivers\Imagick\Driver;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;
use Intervention\Image\Modifiers\CropModifier as GenericCropModifier;
Expand Down Expand Up @@ -47,7 +48,9 @@ public function apply(ImageInterface $image): ImageInterface
if ($frame->native()->getImageAlphaChannel()) {
$canvas->compositeImage(
$frame->native(),
$this->imagemagickMajorVersion() <= 6 ? Imagick::COMPOSITE_DSTIN : Imagick::COMPOSITE_COPYOPACITY,
version_compare(Driver::version(), '7.0.0', '>=') ?
Imagick::COMPOSITE_COPYOPACITY :
Imagick::COMPOSITE_DSTIN,
($crop->pivot()->x() + $this->offset_x) * -1,
($crop->pivot()->y() + $this->offset_y) * -1,
);
Expand All @@ -62,13 +65,4 @@ public function apply(ImageInterface $image): ImageInterface

return $image;
}

private function imagemagickMajorVersion(): int
{
if (preg_match('/^ImageMagick (?P<major>[0-9]+)\./', Imagick::getVersion()['versionString'], $matches) != 1) {
return 0;
}

return intval($matches['major']);
}
}

0 comments on commit cc0b332

Please sign in to comment.