I have an array:
Array
(
[red] => 252
[green] => 168
[blue] => 166
[alpha] => 0
)
It's an output of function imagecolorsforindex.
How can I get a HTML code from these elements? For example: #99CCFF
Strictly speaking you can't, since alpha is not supported. But since the alpha is 0, we can assume that it won't matter. As such, pass each value into sprintf() with a format specifier of %02x for each element.
c = sprintf('#%02x%02x%02x', val['red'], val['green'], val['blue']);
PHP Convert RGB from/to HTML hex color
rgb2html($array[0], $array[1], $array[2])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With