Skip to content

Commit

Permalink
Check if GD is installed
Browse files Browse the repository at this point in the history
  • Loading branch information
endroid committed Oct 8, 2020
1 parent d7bff66 commit 4d36d6b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Writer/PngWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class PngWriter extends AbstractWriter
{
public function writeString(QrCodeInterface $qrCode): string
{
if (!extension_loaded('gd')) {
throw new GenerateImageException('Unable to generate image: check your GD installation');
}

$image = $this->createImage($qrCode->getData(), $qrCode);

$logoPath = $qrCode->getLogoPath();
Expand Down Expand Up @@ -97,8 +101,9 @@ private function createInterpolatedImage($baseImage, array $data, QrCodeInterfac
imagefill($image, 0, 0, $backgroundColor);
imagecopyresampled($image, $baseImage, (int) $data['margin_left'], (int) $data['margin_left'], 0, 0, (int) $data['inner_width'], (int) $data['inner_height'], imagesx($baseImage), imagesy($baseImage));

if($qrCode->getBackgroundColor()['a'] > 0)
imagesavealpha($image, true);
if ($qrCode->getBackgroundColor()['a'] > 0) {
imagesavealpha($image, true);
}

return $image;
}
Expand Down

0 comments on commit 4d36d6b

Please sign in to comment.