Question: I want users on my website to be able to pick a hex colour, and I just want to display white text for dark colours and black text for light colours. Can you work out the brightness from a hex code (preferably PHP)?

Answer: 
I know this is a very old topic, but for users who came from "Google Search", this link may be what they are looking for. I've searched for something like this and I think it's a good idea to post it here:

<https://github.com/mexitek/phpColors>

```
use Mexitek\PHPColors\Color;
// Initialize my color
$myBlue = new Color("#336699");

echo $myBlue->isLight(); // false
echo $myBlue->isDark(); // true

```

That's it.
If you have imagemagick extension activated, you can simply create an ImagickPixel object, call setColor with your hex value, and then call getHSL() (and get the last item of the obtained array I suppose)...