1616use chillerlan \Settings \SettingsContainerInterface ;
1717use function file_get_contents , get_resource_type , imagecolorat , imagecolorsforindex ,
1818 imagecreatefromstring , imagefilter , imagesx , imagesy , is_resource ;
19- use const IMG_FILTER_BRIGHTNESS , IMG_FILTER_CONTRAST , IMG_FILTER_GRAYSCALE , PHP_MAJOR_VERSION ;
19+ use const IMG_FILTER_BRIGHTNESS , IMG_FILTER_CONTRAST , IMG_FILTER_GRAYSCALE , IMG_FILTER_NEGATE , PHP_MAJOR_VERSION ;
2020
2121/**
2222 * This class is used to help decode images from files which arrive as GD Resource
@@ -41,7 +41,7 @@ public function __construct($gdImage, SettingsContainerInterface $options = null
4141
4242 /** @noinspection PhpFullyQualifiedNameUsageInspection */
4343 if (
44- (PHP_MAJOR_VERSION >= 8 && !$ gdImage instanceof \GdImage)
44+ (PHP_MAJOR_VERSION >= 8 && !$ gdImage instanceof \GdImage) // @todo: remove version check in v6
4545 || (PHP_MAJOR_VERSION < 8 && (!is_resource ($ gdImage ) || get_resource_type ($ gdImage ) !== 'gd ' ))
4646 ){
4747 throw new QRCodeDecoderException ('Invalid GD image source. ' ); // @codeCoverageIgnore
@@ -51,23 +51,27 @@ public function __construct($gdImage, SettingsContainerInterface $options = null
5151
5252 $ this ->gdImage = $ gdImage ;
5353
54- $ this ->setLuminancePixels ();
55- }
56-
57- /**
58- *
59- */
60- protected function setLuminancePixels ():void {
61-
6254 if ($ this ->options ->readerGrayscale ){
6355 imagefilter ($ this ->gdImage , IMG_FILTER_GRAYSCALE );
6456 }
6557
58+ if ($ this ->options ->readerInvertColors ){
59+ imagefilter ($ this ->gdImage , IMG_FILTER_NEGATE );
60+ }
61+
6662 if ($ this ->options ->readerIncreaseContrast ){
6763 imagefilter ($ this ->gdImage , IMG_FILTER_BRIGHTNESS , -100 );
6864 imagefilter ($ this ->gdImage , IMG_FILTER_CONTRAST , -100 );
6965 }
7066
67+ $ this ->setLuminancePixels ();
68+ }
69+
70+ /**
71+ *
72+ */
73+ protected function setLuminancePixels ():void {
74+
7175 for ($ j = 0 ; $ j < $ this ->height ; $ j ++){
7276 for ($ i = 0 ; $ i < $ this ->width ; $ i ++){
7377 $ argb = imagecolorat ($ this ->gdImage , $ i , $ j );
0 commit comments