diff --git a/src/Intervention/Image/AbstractDriver.php b/src/Intervention/Image/AbstractDriver.php index b71235ff..ac30e479 100644 --- a/src/Intervention/Image/AbstractDriver.php +++ b/src/Intervention/Image/AbstractDriver.php @@ -35,6 +35,13 @@ abstract class AbstractDriver * @return AbstractColor */ abstract public function parseColor($value); + + /** + * Checks if core module installation is available + * + * @return boolean + */ + abstract protected function coreAvailable(); /** * Initiates new image from given input diff --git a/src/Intervention/Image/Gd/Driver.php b/src/Intervention/Image/Gd/Driver.php index 568b9557..466ecb31 100644 --- a/src/Intervention/Image/Gd/Driver.php +++ b/src/Intervention/Image/Gd/Driver.php @@ -14,6 +14,12 @@ class Driver extends \Intervention\Image\AbstractDriver */ public function __construct(Source $source = null, Encoder $encoder = null) { + if ( ! $this->coreAvailable()) { + throw new \Intervention\Image\Exception\NotSupportedException( + "GD Library extension not available with this PHP installation." + ); + } + $this->source = $source ? $source : new Source; $this->encoder = $encoder ? $encoder : new Encoder; } @@ -50,4 +56,14 @@ class Driver extends \Intervention\Image\AbstractDriver { return new Color($value); } + + /** + * Checks if core module installation is available + * + * @return boolean + */ + protected function coreAvailable() + { + return (extension_loaded('gd') && function_exists('gd_info')); + } } diff --git a/src/Intervention/Image/Imagick/Driver.php b/src/Intervention/Image/Imagick/Driver.php index 32518f25..333cff40 100644 --- a/src/Intervention/Image/Imagick/Driver.php +++ b/src/Intervention/Image/Imagick/Driver.php @@ -14,6 +14,12 @@ class Driver extends \Intervention\Image\AbstractDriver */ public function __construct(Source $source = null, Encoder $encoder = null) { + if ( ! $this->coreAvailable()) { + throw new \Intervention\Image\Exception\NotSupportedException( + "ImageMagick module not available with this PHP installation." + ); + } + $this->source = $source ? $source : new Source; $this->encoder = $encoder ? $encoder : new Encoder; } @@ -56,4 +62,14 @@ class Driver extends \Intervention\Image\AbstractDriver { return new Color($value); } + + /** + * Checks if core module installation is available + * + * @return boolean + */ + protected function coreAvailable() + { + return (extension_loaded('imagick') && class_exists('Imagick')); + } }