Jump to content

Allocating colors globally


ExpertAlmost

Recommended Posts

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:

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

Link to comment
https://forums.phpfreaks.com/topic/142936-allocating-colors-globally/
Share on other sites

My apologies for the poorly communicated question!

 

How do I use imagecolorallocate() to allocate colors with a GLOBAL scope for a single image across functions (passing the image as a function input)?

 

AND, how can I allocate a single color for multiple images without calling imagecolorallocate() multiple times for the same color but a different image name?

 

Hope this is more clear.

 

Thank you for your patience and guidance!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.