Skip to content

Commit dcf125a

Browse files
committed
:octocat: check for loaded extensions
1 parent 6ecb09f commit dcf125a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Output/QRImage.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
namespace chillerlan\QRCode\Output;
1414

15-
use chillerlan\QRCode\QRCode;
15+
use chillerlan\QRCode\Data\QRMatrix;
16+
use chillerlan\QRCode\{QRCode, QRCodeException};
17+
use chillerlan\Settings\SettingsContainerInterface;
1618
use Exception;
1719

1820
use function array_values, base64_encode, call_user_func, count, imagecolorallocate, imagecolortransparent,
@@ -42,6 +44,20 @@ class QRImage extends QROutputAbstract{
4244
*/
4345
protected $image;
4446

47+
/**
48+
* @inheritDoc
49+
*
50+
* @throws \chillerlan\QRCode\QRCodeException
51+
*/
52+
public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
53+
54+
if(!extension_loaded('gd')){
55+
throw new QRCodeException('ext-gd not loaded'); // @codeCoverageIgnore
56+
}
57+
58+
parent::__construct($options, $matrix);
59+
}
60+
4561
/**
4662
* @inheritDoc
4763
*/

src/Output/QRImagick.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
namespace chillerlan\QRCode\Output;
1414

15+
use chillerlan\QRCode\Data\QRMatrix;
16+
use chillerlan\QRCode\QRCodeException;
17+
use chillerlan\Settings\SettingsContainerInterface;
1518
use Imagick, ImagickDraw, ImagickPixel;
1619

1720
use function is_string;
@@ -29,6 +32,19 @@ class QRImagick extends QROutputAbstract{
2932
*/
3033
protected $imagick;
3134

35+
/**
36+
* @inheritDoc
37+
* @throws \chillerlan\QRCode\QRCodeException
38+
*/
39+
public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
40+
41+
if(!extension_loaded('imagick')){
42+
throw new QRCodeException('ext-imagick not loaded'); // @codeCoverageIgnore
43+
}
44+
45+
parent::__construct($options, $matrix);
46+
}
47+
3248
/**
3349
* @inheritDoc
3450
*/

0 commit comments

Comments
 (0)