I have had a case where I got the alpha from a raw RGBA pallete. This was stored as 8bit where 0 is completely transparant, and 255 is complete opaque.This is impossible to use with imagecolorallocatealpha() as it requires a 7bit int where 0 is completely opaque and 127 is completely transparant (otherway around)You can solve this by subtracting 255, removing the negative sign (either by converting to string and substr($alpha, 1) or some other way) and then bitshifting the answer to the right by one 1 bit.

If you need to calculate the integer representation of a color with an alpha channel, without initialising an image and using the imagecolorallocatealpha function. Then this function might be of some help: