16
16
use chillerlan \Settings \SettingsContainerInterface ;
17
17
use function file_get_contents , get_resource_type , imagecolorat , imagecolorsforindex ,
18
18
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 ;
20
20
21
21
/**
22
22
* 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
41
41
42
42
/** @noinspection PhpFullyQualifiedNameUsageInspection */
43
43
if (
44
- (PHP_MAJOR_VERSION >= 8 && !$ gdImage instanceof \GdImage)
44
+ (PHP_MAJOR_VERSION >= 8 && !$ gdImage instanceof \GdImage) // @todo: remove version check in v6
45
45
|| (PHP_MAJOR_VERSION < 8 && (!is_resource ($ gdImage ) || get_resource_type ($ gdImage ) !== 'gd ' ))
46
46
){
47
47
throw new QRCodeDecoderException ('Invalid GD image source. ' ); // @codeCoverageIgnore
@@ -51,23 +51,27 @@ public function __construct($gdImage, SettingsContainerInterface $options = null
51
51
52
52
$ this ->gdImage = $ gdImage ;
53
53
54
- $ this ->setLuminancePixels ();
55
- }
56
-
57
- /**
58
- *
59
- */
60
- protected function setLuminancePixels ():void {
61
-
62
54
if ($ this ->options ->readerGrayscale ){
63
55
imagefilter ($ this ->gdImage , IMG_FILTER_GRAYSCALE );
64
56
}
65
57
58
+ if ($ this ->options ->readerInvertColors ){
59
+ imagefilter ($ this ->gdImage , IMG_FILTER_NEGATE );
60
+ }
61
+
66
62
if ($ this ->options ->readerIncreaseContrast ){
67
63
imagefilter ($ this ->gdImage , IMG_FILTER_BRIGHTNESS , -100 );
68
64
imagefilter ($ this ->gdImage , IMG_FILTER_CONTRAST , -100 );
69
65
}
70
66
67
+ $ this ->setLuminancePixels ();
68
+ }
69
+
70
+ /**
71
+ *
72
+ */
73
+ protected function setLuminancePixels ():void {
74
+
71
75
for ($ j = 0 ; $ j < $ this ->height ; $ j ++){
72
76
for ($ i = 0 ; $ i < $ this ->width ; $ i ++){
73
77
$ argb = imagecolorat ($ this ->gdImage , $ i , $ j );
0 commit comments