diff --git a/src/Drivers/Gd/Driver.php b/src/Drivers/Gd/Driver.php index 3ce1bec2..13d6f721 100644 --- a/src/Drivers/Gd/Driver.php +++ b/src/Drivers/Gd/Driver.php @@ -149,4 +149,14 @@ public function supports(string|Format|FileExtension|MediaType $identifier): boo default => false, }; } + + /** + * Return version of GD library + * + * @return string + */ + public static function version(): string + { + return gd_info()['GD Version']; + } } diff --git a/src/Drivers/Imagick/Driver.php b/src/Drivers/Imagick/Driver.php index 88f1d90c..8f0e3c0e 100644 --- a/src/Drivers/Imagick/Driver.php +++ b/src/Drivers/Imagick/Driver.php @@ -84,6 +84,7 @@ public function __construct( protected DriverInterface $driver, public Imagick $imagick ) { + // } /** @@ -151,4 +152,23 @@ public function supports(string|Format|FileExtension|MediaType $identifier): boo return count(Imagick::queryFormats($format->name)) >= 1; } + + /** + * Return version of ImageMagick library + * + * @throws DriverException + * @return string + */ + public static function version(): string + { + $pattern = '/^ImageMagick (?P(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' . + '(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?' . + '(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/'; + + if (preg_match($pattern, Imagick::getVersion()['versionString'], $matches) !== 1) { + throw new DriverException('Unable to read ImageMagick version number.'); + } + + return $matches['version']; + } } diff --git a/tests/Unit/Drivers/Gd/DriverTest.php b/tests/Unit/Drivers/Gd/DriverTest.php index ce009584..174a5293 100644 --- a/tests/Unit/Drivers/Gd/DriverTest.php +++ b/tests/Unit/Drivers/Gd/DriverTest.php @@ -206,4 +206,9 @@ public static function supportsDataProvider(): Generator yield [false, 'foo']; yield [false, '']; } + + public function testVersion(): void + { + $this->assertTrue(is_string($this->driver->version())); + } } diff --git a/tests/Unit/Drivers/Imagick/DriverTest.php b/tests/Unit/Drivers/Imagick/DriverTest.php index c9465832..494b002b 100644 --- a/tests/Unit/Drivers/Imagick/DriverTest.php +++ b/tests/Unit/Drivers/Imagick/DriverTest.php @@ -206,4 +206,9 @@ public static function supportsDataProvider(): Generator yield [false, 'foo']; yield [false, '']; } + + public function testVersion(): void + { + $this->assertTrue(is_string($this->driver->version())); + } }