Page 1 of 1

Allocating colors globally

Posted: Thu Jan 29, 2009 3:10 am
by ExpertAlmost
Good morning!

I create several images in several different functions in several different files. I use imagecolorallocate() for 15 colors in every function for every image. What a mess!

Is there some way to clean that up? Is there some way to make colors global:
1) For a single image across functions?
2) For ALL images and across functions??

I try variations of the following but nothing works:

Code: Select all

func_one() {
     // create $Img1
     $black = imagecolorallocate($Img1, 0, 0, 0);
     // more code follows
}
 
func_two() {
    global $black;      //this works for other variables but not for colors it seems.
    // more code==> BUT $black color is NOT recognized for $Img1 or any other image, even if I pass $Img1 into func_two.
}
Any help to clean up my code would be greatly appreciated!

Thank you Experts-One-And-All