|
15 | 15 | use chillerlan\QRCode\Data\QRMatrix; |
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | use ErrorException, Throwable; |
18 | | -use function count, extension_loaded, imagecolorallocate, imagecolortransparent, imagecreatetruecolor, |
19 | | - imagedestroy, imagefilledellipse, imagefilledrectangle, imagegif, imagejpeg, imagepng, imagescale, is_array, is_numeric, |
20 | | - max, min, ob_end_clean, ob_get_contents, ob_start, restore_error_handler, set_error_handler; |
| 18 | +use function array_values, count, extension_loaded, imagecolorallocate, imagecolortransparent, imagecreatetruecolor, |
| 19 | + imagedestroy, imagefilledellipse, imagefilledrectangle, imagegif, imagejpeg, imagepng, imagescale, intval, |
| 20 | + is_array, is_numeric, max, min, ob_end_clean, ob_get_contents, ob_start, restore_error_handler, set_error_handler; |
21 | 21 |
|
22 | 22 | /** |
23 | 23 | * Converts the matrix into GD images, raw or base64 output (requires ext-gd) |
@@ -89,29 +89,41 @@ public static function moduleValueIsValid($value):bool{ |
89 | 89 | } |
90 | 90 |
|
91 | 91 | // check the first 3 values of the array |
92 | | - for($i = 0; $i < 3; $i++){ |
93 | | - if(!is_numeric($value[$i])){ |
| 92 | + foreach(array_values($value) as $i => $val){ |
| 93 | + |
| 94 | + if($i > 2){ |
| 95 | + break; |
| 96 | + } |
| 97 | + |
| 98 | + if(!is_numeric($val)){ |
94 | 99 | return false; |
95 | 100 | } |
| 101 | + |
96 | 102 | } |
97 | 103 |
|
98 | 104 | return true; |
99 | 105 | } |
100 | 106 |
|
101 | 107 | /** |
| 108 | + * @param array $value |
| 109 | + * |
102 | 110 | * @inheritDoc |
103 | 111 | * @throws \chillerlan\QRCode\Output\QRCodeOutputException |
104 | 112 | */ |
105 | 113 | protected function getModuleValue($value):int{ |
106 | | - $v = []; |
| 114 | + $values = []; |
| 115 | + |
| 116 | + foreach(array_values($value) as $i => $val){ |
| 117 | + |
| 118 | + if($i > 2){ |
| 119 | + break; |
| 120 | + } |
107 | 121 |
|
108 | | - for($i = 0; $i < 3; $i++){ |
109 | | - // clamp value |
110 | | - $v[] = (int)max(0, min(255, $value[$i])); |
| 122 | + $values[] = max(0, min(255, intval($val))); |
111 | 123 | } |
112 | 124 |
|
113 | 125 | /** @phan-suppress-next-line PhanParamTooFewInternalUnpack */ |
114 | | - $color = imagecolorallocate($this->image, ...$v); |
| 126 | + $color = imagecolorallocate($this->image, ...$values); |
115 | 127 |
|
116 | 128 | if($color === false){ |
117 | 129 | throw new QRCodeOutputException('could not set color: imagecolorallocate() error'); |
|
0 commit comments