Skip to content

Commit

Permalink
Fix copying of alpha channel for different Imagick versions
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Jan 10, 2025
1 parent de66c37 commit a0b27ef
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Drivers/Imagick/Modifiers/CropModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function apply(ImageInterface $image): ImageInterface

$canvas->compositeImage(
$frame->native(),
Imagick::COMPOSITE_COPYOPACITY,
$this->imagemagickMajorVersion() <= 6 ? Imagick::COMPOSITE_DSTIN : Imagick::COMPOSITE_COPYOPACITY,
($crop->pivot()->x() + $this->offset_x) * -1,
($crop->pivot()->y() + $this->offset_y) * -1,
);
Expand All @@ -45,4 +45,13 @@ 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);

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ImageMagick 6.9.12-55

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.

Check failure on line 55 in src/Drivers/Imagick/Modifiers/CropModifier.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ImageMagick 7.1.1-32

Offset 'major' on array{0: string, major: numeric-string, 1: numeric-string} on left side of ?? always exists and is not nullable.
}
}

0 comments on commit a0b27ef

Please sign in to comment.