Jelajahi Sumber

:wrench: fix QRGdImage::checkGD() to not throw when using default or custom output

smiley 2 tahun lalu
induk
melakukan
502dd697f5
1 mengubah file dengan 14 tambahan dan 7 penghapusan
  1. 14 7
      src/Output/QRGdImage.php

+ 14 - 7
src/Output/QRGdImage.php

@@ -81,14 +81,21 @@ class QRGdImage extends QROutputAbstract{
 			throw new QRCodeOutputException('ext-gd not loaded');
 			throw new QRCodeOutputException('ext-gd not loaded');
 		}
 		}
 
 
+		$modes = [
+			self::GDIMAGE_BMP  => 'BMP Support',
+			self::GDIMAGE_GIF  => 'GIF Create Support',
+			self::GDIMAGE_JPG  => 'JPEG Support',
+			self::GDIMAGE_PNG  => 'PNG Support',
+			self::GDIMAGE_WEBP => 'WebP Support',
+		];
+
+		// likely using default or custom output
+		if(!isset($modes[$this->options->outputType])){
+			return;
+		}
+
 		$info = gd_info();
 		$info = gd_info();
-		$mode = [
-			        self::GDIMAGE_BMP  => 'BMP Support',
-			        self::GDIMAGE_GIF  => 'GIF Create Support',
-			        self::GDIMAGE_JPG  => 'JPEG Support',
-			        self::GDIMAGE_PNG  => 'PNG Support',
-			        self::GDIMAGE_WEBP => 'WebP Support',
-		        ][$this->options->outputType];
+		$mode = $modes[$this->options->outputType];
 
 
 		if(!isset($info[$mode]) || $info[$mode] !== true){
 		if(!isset($info[$mode]) || $info[$mode] !== true){
 			throw new QRCodeOutputException(sprintf('output mode "%s" not supported', $this->options->outputType));
 			throw new QRCodeOutputException(sprintf('output mode "%s" not supported', $this->options->outputType));