浏览代码

:octocat: QRGdImage::checkGD(): use imagetypes() instead of gd_info()

smiley 2 年之前
父节点
当前提交
443bd5589f
共有 1 个文件被更改,包括 10 次插入10 次删除
  1. 10 10
      src/Output/QRGdImage.php

+ 10 - 10
src/Output/QRGdImage.php

@@ -16,10 +16,11 @@ use chillerlan\QRCode\QROptions;
 use chillerlan\QRCode\Data\QRMatrix;
 use chillerlan\QRCode\Data\QRMatrix;
 use chillerlan\Settings\SettingsContainerInterface;
 use chillerlan\Settings\SettingsContainerInterface;
 use ErrorException, GdImage, Throwable;
 use ErrorException, GdImage, Throwable;
-use function array_values, count, extension_loaded, gd_info, imagecolorallocate, imagecolortransparent,
+use function array_values, count, extension_loaded, imagecolorallocate, imagecolortransparent,
 	imagecreatetruecolor, imagedestroy, imagefilledellipse, imagefilledrectangle,
 	imagecreatetruecolor, imagedestroy, imagefilledellipse, imagefilledrectangle,
-	imagescale, intdiv, intval, is_array, is_numeric, max, min, ob_end_clean, ob_get_contents, ob_start,
+	imagescale, imagetypes, intdiv, intval, is_array, is_numeric, max, min, ob_end_clean, ob_get_contents, ob_start,
 	restore_error_handler, set_error_handler, sprintf;
 	restore_error_handler, set_error_handler, sprintf;
+use const IMG_AVIF, IMG_BMP, IMG_GIF, IMG_JPG, IMG_PNG, IMG_WEBP;
 
 
 /**
 /**
  * Converts the matrix into GD images, raw or base64 output (requires ext-gd)
  * Converts the matrix into GD images, raw or base64 output (requires ext-gd)
@@ -83,12 +84,12 @@ abstract class QRGdImage extends QROutputAbstract{
 		}
 		}
 
 
 		$modes = [
 		$modes = [
-			QRGdImageAVIF::class => 'AVIF Support',
-			QRGdImageBMP::class  => 'BMP Support',
-			QRGdImageGIF::class  => 'GIF Create Support',
-			QRGdImageJPEG::class => 'JPEG Support',
-			QRGdImagePNG::class  => 'PNG Support',
-			QRGdImageWEBP::class => 'WebP Support',
+			QRGdImageAVIF::class => IMG_AVIF,
+			QRGdImageBMP::class  => IMG_BMP,
+			QRGdImageGIF::class  => IMG_GIF,
+			QRGdImageJPEG::class => IMG_JPG,
+			QRGdImagePNG::class  => IMG_PNG,
+			QRGdImageWEBP::class => IMG_WEBP,
 		];
 		];
 
 
 		// likely using custom output/manual invocation
 		// likely using custom output/manual invocation
@@ -96,10 +97,9 @@ abstract class QRGdImage extends QROutputAbstract{
 			return;
 			return;
 		}
 		}
 
 
-		$info = gd_info();
 		$mode = $modes[$this->options->outputInterface];
 		$mode = $modes[$this->options->outputInterface];
 
 
-		if(!isset($info[$mode]) || $info[$mode] !== true){
+		if((imagetypes() & $mode) !== $mode){
 			throw new QRCodeOutputException(sprintf('output mode "%s" not supported', $this->options->outputInterface));
 			throw new QRCodeOutputException(sprintf('output mode "%s" not supported', $this->options->outputInterface));
 		}
 		}