Forum Moderators: coopster

Message Too Old, No Replies

Convert HEX colour to rgb

         

benihana

11:58 am on Nov 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Im trying to convert a hex ref to rgb to use with the gd image manipulation.

try:

$rgb = chunk_split('ff0000', 2);
// convert hex values to decimal
$r = hexdec($rgb[0]);
$g = hexdec($rgb[1]);
$b = hexdec($rgb[2]);
echo($r);
echo($g);
echo($b);

gives:

15150

where id expect 25500

any pointers?

ta

adb64

12:08 pm on Nov 8, 2005 (gmt 0)

10+ Year Member



I think you will need to use str_split [php.net] and not chunk_split [php.net] as the latter one will insert \r\n sequences into your string.

benihana

1:02 pm on Nov 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks!

:)