diff --git a/composer.json b/composer.json index 493d79ee8..62b19ece8 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ ], "require": { "php": "^7.4", - "ext-gd": "*", "ext-json": "*", "ext-mbstring": "*", "chillerlan/php-settings-container": "^1.2" diff --git a/src/Output/QRImage.php b/src/Output/QRImage.php index eb67a46e5..5cc93d4f4 100644 --- a/src/Output/QRImage.php +++ b/src/Output/QRImage.php @@ -9,15 +9,18 @@ * @copyright 2015 Smiley * @license MIT * + * @noinspection PhpComposerExtensionStubsInspection * @noinspection PhpUnused */ 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, +use function array_values, base64_encode, call_user_func, count, extension_loaded, imagecolorallocate, imagecolortransparent, imagecreatetruecolor, imagedestroy, imagefilledrectangle, imagegif, imagejpeg, imagepng, in_array, is_array, ob_end_clean, ob_get_contents, ob_start, range, sprintf; @@ -28,6 +31,18 @@ use function array_values, base64_encode, call_user_func, count, imagecoloralloc */ class QRImage extends QROutputAbstract{ + /** + * @inheritDoc + */ + public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ + + if(!extension_loaded('gd')){ + throw new QRCodeException('ext-gd not loaded'); + } + + parent::__construct($options, $matrix); + } + /** * GD image types that support transparency * diff --git a/src/Output/QRImagick.php b/src/Output/QRImagick.php index 9afd5df40..c68bbab28 100644 --- a/src/Output/QRImagick.php +++ b/src/Output/QRImagick.php @@ -14,9 +14,12 @@ 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; +use function extension_loaded, is_string; /** * ImageMagick output module (requires ext-imagick) @@ -26,6 +29,18 @@ use function is_string; */ class QRImagick extends QROutputAbstract{ + /** + * @inheritDoc + */ + public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){ + + if(!extension_loaded('imagick')){ + throw new QRCodeException('ext-imagick not loaded'); + } + + parent::__construct($options, $matrix); + } + /** * @inheritDoc */