Skip to content

Commit

Permalink
🔧 fix QRGdImage::checkGD() to not throw when using default or custom …
Browse files Browse the repository at this point in the history
…output
  • Loading branch information
codemasher committed Sep 8, 2023
1 parent af284bf commit 502dd69
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Output/QRGdImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,21 @@ protected function checkGD():void{
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();
$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){
throw new QRCodeOutputException(sprintf('output mode "%s" not supported', $this->options->outputType));
Expand Down

0 comments on commit 502dd69

Please sign in to comment.