views:

75

answers:

1

I have a PHP variable which contains information about color. For example $text_color = "ff90f3". Now I want to give this color to imagecolorallocate. The imagecolorallocate works like that:

imagecolorallocate($im, 0xFF, 0xFF, 0xFF);

So, I am trying to do the following:

$r_bg = bin2hex("0x".substr($text_color,0,2));
$g_bg = bin2hex("0x".substr($text_color,2,2));
$b_bg = bin2hex("0x".substr($text_color,4,2));
$bg_col = imagecolorallocate($image, $r_bg, $g_bg, $b_bg);

It does not work. Why? I try it also without bin2hex, it also did not work. Can anybody help me with that?

A: 

Use hexdec() (exemple : hexdec("a0"))

http://fr2.php.net/manual/en/function.hexdec.php

Serty Oan
It works. Thanks!
Roman