🚿 remove ext-gd requirement, check extension_loaded instead

This commit is contained in:
codemasher
2020-04-05 05:18:17 +02:00
parent cae601fff6
commit dcf860824f
3 changed files with 33 additions and 4 deletions
-1
View File
@@ -25,7 +25,6 @@
],
"require": {
"php": "^7.4",
"ext-gd": "*",
"ext-json": "*",
"ext-mbstring": "*",
"chillerlan/php-settings-container": "^1.2"
+17 -2
View File
@@ -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
*
+16 -1
View File
@@ -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
*/