Просмотр исходного кода

:shower: remove ext-gd requirement, check extension_loaded instead

codemasher 5 лет назад
Родитель
Сommit
dcf860824f
3 измененных файлов с 33 добавлено и 4 удалено
  1. 0 1
      composer.json
  2. 17 2
      src/Output/QRImage.php
  3. 16 1
      src/Output/QRImagick.php

+ 0 - 1
composer.json

@@ -25,7 +25,6 @@
 	],
 	"require": {
 		"php": "^7.4",
-		"ext-gd": "*",
 		"ext-json": "*",
 		"ext-mbstring": "*",
 		"chillerlan/php-settings-container": "^1.2"

+ 17 - 2
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
 	 *

+ 16 - 1
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
 	 */