Allocating colors globally

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
ExpertAlmost
Forum Commoner
Posts: 41
Joined: Mon Oct 20, 2008 12:26 am

Allocating colors globally

Post 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
Post Reply