Something rong with ImageColorAllocate

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Something rong with ImageColorAllocate

Post 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?
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

Code: Select all

$blue = ImageColorAllocate($image , 220, 220, 220);
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post 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]);
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Post by Pineriver »

Perfect, Thanks!
Post Reply