Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Driver::version() #1417

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Drivers/Gd/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
20 changes: 20 additions & 0 deletions src/Drivers/Imagick/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function __construct(
protected DriverInterface $driver,
public Imagick $imagick
) {
//
}

/**
Expand Down Expand Up @@ -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<version>(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'];
}
}
5 changes: 5 additions & 0 deletions tests/Unit/Drivers/Gd/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
5 changes: 5 additions & 0 deletions tests/Unit/Drivers/Imagick/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}
Loading