| @@ 18-72 (lines=55) @@ | ||
| 15 | * |
|
| 16 | * @package GravityMedia\Magickly\Gmagick |
|
| 17 | */ |
|
| 18 | class Magickly implements MagicklyInterface |
|
| 19 | { |
|
| 20 | /** |
|
| 21 | * @var string |
|
| 22 | */ |
|
| 23 | private static $version; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * Create Magickly object. |
|
| 27 | * |
|
| 28 | * @throws RuntimeException |
|
| 29 | */ |
|
| 30 | public function __construct() |
|
| 31 | { |
|
| 32 | if (!class_exists('Gmagick')) { |
|
| 33 | throw new RuntimeException('Gmagick not installed'); |
|
| 34 | } |
|
| 35 | ||
| 36 | $version = $this->getVersion(); |
|
| 37 | if (version_compare('1.3.0', $version) > 0) { |
|
| 38 | throw new RuntimeException(sprintf('ImageMagick version 1.3.0 or higher is required, %s provided', $version)); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Get version. |
|
| 44 | * |
|
| 45 | * @return string |
|
| 46 | */ |
|
| 47 | public function getVersion() |
|
| 48 | { |
|
| 49 | if (null === self::$version) { |
|
| 50 | $gmagick = new \Gmagick(); |
|
| 51 | $version = $gmagick->getVersion(); |
|
| 52 | ||
| 53 | list(self::$version) = sscanf($version['versionString'], 'GraphicsMagick %s %04d-%02d-%02d %s %s'); |
|
| 54 | } |
|
| 55 | ||
| 56 | return self::$version; |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | */ |
|
| 62 | public function open($path) |
|
| 63 | { |
|
| 64 | try { |
|
| 65 | $gmagick = new \Gmagick($path); |
|
| 66 | } catch (\GmagickException $exception) { |
|
| 67 | throw new RuntimeException(sprintf('Unable to open image %s', $path), 0, $exception); |
|
| 68 | } |
|
| 69 | ||
| 70 | return new Image($gmagick); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||
| @@ 18-72 (lines=55) @@ | ||
| 15 | * |
|
| 16 | * @package GravityMedia\Magickly\Imagick |
|
| 17 | */ |
|
| 18 | class Magickly implements MagicklyInterface |
|
| 19 | { |
|
| 20 | /** |
|
| 21 | * @var string |
|
| 22 | */ |
|
| 23 | private static $version; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * Create Magickly object. |
|
| 27 | * |
|
| 28 | * @throws RuntimeException |
|
| 29 | */ |
|
| 30 | public function __construct() |
|
| 31 | { |
|
| 32 | if (!class_exists('Imagick')) { |
|
| 33 | throw new RuntimeException('Imagick not installed'); |
|
| 34 | } |
|
| 35 | ||
| 36 | $version = $this->getVersion(); |
|
| 37 | if (version_compare('6.2.9', $version) > 0) { |
|
| 38 | throw new RuntimeException(sprintf('ImageMagick version 6.2.9 or higher is required, %s provided', $version)); |
|
| 39 | } |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Get version. |
|
| 44 | * |
|
| 45 | * @return string |
|
| 46 | */ |
|
| 47 | public function getVersion() |
|
| 48 | { |
|
| 49 | if (null === self::$version) { |
|
| 50 | $imagick = new \Imagick(); |
|
| 51 | $version = $imagick->getVersion(); |
|
| 52 | ||
| 53 | list(self::$version) = sscanf($version['versionString'], 'ImageMagick %s %04d-%02d-%02d %s %s'); |
|
| 54 | } |
|
| 55 | ||
| 56 | return self::$version; |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * {@inheritdoc} |
|
| 61 | */ |
|
| 62 | public function open($path) |
|
| 63 | { |
|
| 64 | try { |
|
| 65 | $imagick = new \Imagick($path); |
|
| 66 | } catch (\ImagickException $exception) { |
|
| 67 | throw new RuntimeException(sprintf('Unable to open image %s', $path), 0, $exception); |
|
| 68 | } |
|
| 69 | ||
| 70 | return new Image($imagick); |
|
| 71 | } |
|
| 72 | } |
|
| 73 | ||