From dcf125a8b9cd2cd1b1d53a63a8a9554255c760b8 Mon Sep 17 00:00:00 2001 From: codemasher Date: Wed, 18 Nov 2020 17:09:13 +0100 Subject: [PATCH] :octocat: check for loaded extensions --- src/Output/QRImage.php | 18 +++++++++++++++++- src/Output/QRImagick.php | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index 6263568ee..d104a85d2 100644 --- a/src/Output/QRImage.php +++ b/src/Output/QRImage.php @@ -12,7 +12,9 @@ namespace chillerlan\QRCode\Output; -use chillerlan\QRCode\QRCode; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\{QRCode, QRCodeException}; +use chillerlan\Settings\SettingsContainerInterface; use Exception; use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent, @@ -42,6 +44,20 @@ class QRImage extends QROutputAbstract{ */ protected $image; + /** + * @inheritDoc + * + * @throws \chillerlan\QRCode\QRCodeException + */ + public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ + + if(!extension_loaded('gd')){ + throw new QRCodeException('ext-gd not loaded'); // @codeCoverageIgnore + } + + parent::__construct($options, $matrix); + } + /** * @inheritDoc */ diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index 4c2a8c3b7..79f4ae334 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -12,6 +12,9 @@ namespace chillerlan\QRCode\Output; +use chillerlan\QRCode\Data\QRMatrix; +use chillerlan\QRCode\QRCodeException; +use chillerlan\Settings\SettingsContainerInterface; use Imagick, ImagickDraw, ImagickPixel; use function is_string; @@ -29,6 +32,19 @@ class QRImagick extends QROutputAbstract{ */ protected $imagick; + /** + * @inheritDoc + * @throws \chillerlan\QRCode\QRCodeException + */ + public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ + + if(!extension_loaded('imagick')){ + throw new QRCodeException('ext-imagick not loaded'); // @codeCoverageIgnore + } + + parent::__construct($options, $matrix); + } + /** * @inheritDoc */