verbb / color-mixer

A set of Twig filters for modifying hex colors in Craft CMS.
MIT License
12 stars 4 forks source link

_rgbtoHex needs to check strlen like _hslToHex does #6

Closed matthisamoto closed 4 years ago

matthisamoto commented 4 years ago

First found this via mix using basic red #FF0000 and blue #0000FF and a mixture of values, and end up with a bunch of hex values with fewer than six digits, some of which simply don't work at all.

Reading through the twig extensions, the _hslToHex() function works to prevent this right before the return value. I ended up rewriting it to work with _rgbToHex().

I think this works as the result seems correct.

// Make sure we get 2 digits for decimals
$hex[0] = (strlen("".$hex[0])===1) ? "0".$hex[0]:$hex[0];
$hex[1] = (strlen("".$hex[1])===1) ? "0".$hex[1]:$hex[1];
$hex[2] = (strlen("".$hex[2])===1) ? "0".$hex[2]:$hex[2];
whoisjuan commented 4 years ago

@matthisamoto Looks good to me. Thanks. Merging it.