1
votes

In additive color mixing primary colors are Red, Green and Blue (RGB).

Red    = #ff0000
Green  = #00ff00
Blue   = #0000ff

Combining Red (#ff0000) and Green (#00ff00) makes Yellow (#ffff00)

Is there some formula to calulate the hex code of a color resulting from the combination of two others ?

Something like #ff0000 + #00ff00 when applied to such a formula gives #ffff00

1

1 Answers

7
votes

You can add two HEX string like this in PHP:

$red = "FF0000";
$green = "00FF00";

$yellow = dechex(hexdec($red) + hexdec($green));

echo $yellow;

Live Demo

What that snippet is basically doing is converting the hex strings to numbers, adding them together, and then converting the sum back to a hex string.

Reference Links:

hexdec | dechex