GD and deriving some hex codes of lighter versions of a colour

I am doing an colour swap in GD, which is fine for the solid colour of the image.

There are some versions of the colour and i would like to do the same with the colour swap.

Is there a way to get the HEX or RGB values for different opacity of a colour?

ie. if i wanted to get the colour code for #ff0000 but at 50% opacity, is there a way to get that from GD or another function?

ah right, so there’s some formulas for the changing of the opacity of a HEX?

You are going have to do some math…which is currently unavailable to me right now.