Skip to content

Commit 443bd55

Browse files
committed
:octocat: QRGdImage::checkGD(): use imagetypes() instead of gd_info()
1 parent ded4a12 commit 443bd55

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/Output/QRGdImage.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
use chillerlan\QRCode\Data\QRMatrix;
1717
use chillerlan\Settings\SettingsContainerInterface;
1818
use ErrorException, GdImage, Throwable;
19-
use function array_values, count, extension_loaded, gd_info, imagecolorallocate, imagecolortransparent,
19+
use function array_values, count, extension_loaded, imagecolorallocate, imagecolortransparent,
2020
imagecreatetruecolor, imagedestroy, imagefilledellipse, imagefilledrectangle,
21-
imagescale, intdiv, intval, is_array, is_numeric, max, min, ob_end_clean, ob_get_contents, ob_start,
21+
imagescale, imagetypes, intdiv, intval, is_array, is_numeric, max, min, ob_end_clean, ob_get_contents, ob_start,
2222
restore_error_handler, set_error_handler, sprintf;
23+
use const IMG_AVIF, IMG_BMP, IMG_GIF, IMG_JPG, IMG_PNG, IMG_WEBP;
2324

2425
/**
2526
* Converts the matrix into GD images, raw or base64 output (requires ext-gd)
@@ -83,23 +84,22 @@ protected function checkGD():void{
8384
}
8485

8586
$modes = [
86-
QRGdImageAVIF::class => 'AVIF Support',
87-
QRGdImageBMP::class => 'BMP Support',
88-
QRGdImageGIF::class => 'GIF Create Support',
89-
QRGdImageJPEG::class => 'JPEG Support',
90-
QRGdImagePNG::class => 'PNG Support',
91-
QRGdImageWEBP::class => 'WebP Support',
87+
QRGdImageAVIF::class => IMG_AVIF,
88+
QRGdImageBMP::class => IMG_BMP,
89+
QRGdImageGIF::class => IMG_GIF,
90+
QRGdImageJPEG::class => IMG_JPG,
91+
QRGdImagePNG::class => IMG_PNG,
92+
QRGdImageWEBP::class => IMG_WEBP,
9293
];
9394

9495
// likely using custom output/manual invocation
9596
if(!isset($modes[$this->options->outputInterface])){
9697
return;
9798
}
9899

99-
$info = gd_info();
100100
$mode = $modes[$this->options->outputInterface];
101101

102-
if(!isset($info[$mode]) || $info[$mode] !== true){
102+
if((imagetypes() & $mode) !== $mode){
103103
throw new QRCodeOutputException(sprintf('output mode "%s" not supported', $this->options->outputInterface));
104104
}
105105

0 commit comments

Comments
 (0)