3

After working with a lot of GD recently (for some fairly large scale projects for work) I had been dealing with RGB codes that I am not so accustomed to.

My co-workers and I had been suffering some what to find a good method to do this without resorting to a makeshift 'hex to rgb' function with arrays for just a simple function.

There must be a way?

hakre
  • 193,403
  • 52
  • 435
  • 836
John
  • 1,110
  • 3
  • 14
  • 28
  • 1
    Possible Duplicate: http://stackoverflow.com/questions/3623176/php-allocate-color-without-image-resource – Nullw0rm Sep 27 '10 at 15:28

1 Answers1

3

If I am aware imagecolorallocate() only returns a hex representation to be used by the other GD functions, as the library is a bit lower level than PHP of course it works with hex values directly, so there raised a need for an intermediate function to assign a colour.

The following should be equivalent:

$im = imagecreatetruecolor("200", "100");
$white = imagecolorallocate($im, 255, 255, 255);
$white = 0x00FFFFFF;
$alphagreen = imagecolorallocatealpha($im, 0, 255, 0, 64); 
$alphagreen = 0x4000FF00;
Nullw0rm
  • 913
  • 1
  • 6
  • 13