EndroidQrCodeProvider: allow transparent for color#146
EndroidQrCodeProvider: allow transparent for color#146Buffele wants to merge 1 commit intoRobThree:masterfrom Buffele:endroid-transparent-color
Conversation
|
Hello, Thank you for your contribution. Please also document this functionality in the documentation. |
willpower232
left a comment
There was a problem hiding this comment.
Great idea, thanks for the fix. I always forget transparency in PHP is sort of backwards!
Also passing non-hex characters to hexdec (i.e. tr, an, sp) currently raises a deprecation warning so probably something else to catch in the future when they make it a more dramatic failure.
Would it be worth adding some check to confirm that $split is exactly 3 elements long too? Or perhaps checking that $color is exactly 6 characters if it isn't transparent...
|
Maybe I'm mistaken but Endroid QR appears to support Alpha? Then shouldn't this work? $split = str_split($color, 2);
if (sizeof($split) >= 3) {
$r = hexdec($split[0]);
$g = hexdec($split[1]);
$b = hexdec($split[2]);
$a = sizeof($split) >= 4 ? hexdec($split[3]) : 0;
}Handling could be a lot better, maybe even a regex. But the general idea should work, shouldn't it? Edit: function parseColor(string $color) : Color {
if (preg_match('/^#?([0-9a-f]{3,8})$/i', trim($color), $matches) !== false) {
$len = strlen($matches[1]);
if ($len !== 5 && $len !== 7) {
list($r, $g, $b, $a) = str_split($matches[1], $len <= 4 ? 1 : 2);
return new Color(hexdec($r), hexdec($g), hexdec($b), hexdec($a));
}
}
throw new Exception('Invalid color format');
}Should handle optional starting |
|
@Buffele ? |
This enables support for the EndroidQrCodeProvider to allow
transparentto be passed forcolororbgcolor.It is useful for
bgcolor, but probably not too much forcolor.That could be restricted. However, I do not really think that is needed.