Page 1 of 1

Something rong with ImageColorAllocate

Posted: Wed Aug 20, 2003 4:19 pm
by Pineriver
Hi, I am trying to have a variable passed from a webpage to control the RBG color of text, when i try controling it with a variable tells me Wrong parameter count for imagecolorallocate,
when I try putting it the value for the color, it works fine.

Code: Select all

Header("Content-type: image/jpeg"); 
$image = imagecreatefromjpeg("image.jpg"); 
$RGB_color = "220,220,220";
$blue = ImageColorAllocate($image , $RGB_color);
ImageString($image,5,5,110,'Devnetwork',$blue);
ImageJPEG($image);
Can anyone tell me what I am doing rong?

Posted: Thu Aug 21, 2003 3:18 am
by Wayne

Code: Select all

$blue = ImageColorAllocate($image , 220, 220, 220);

Posted: Thu Aug 21, 2003 4:13 am
by pootergeist
for colour passing, you might like to pass #hex and run an auto convert.
as mentioned by Wayne, passing a comma seperated string into a function does not effect the same as passing three parameters, so you'd need to array build the hex

// -> input $hexrgb eg 45FD45
$rgb = array(
hexdec(substr($hexrgb,0,2)),
hexdec(substr($hexrgb,2,2)),
hexdec(substr($hexrgb,4,2)));
$new_colour = imagecolorallocate($image, $rgb[0], $rgb[1], $rgb[2]);

Posted: Thu Aug 21, 2003 10:12 am
by Pineriver
Perfect, Thanks!