Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a lighter version of a colour using PHP?

Hello fellow earthlings. A quesion about RGB color and its usefulness in a simple tiny php code:

Imagine I have variable $colorA containning a valid six char color. say B1B100, a greenish natural color. Now If I would like to make a new color from that, which is, say, ten steps lighter thatn that original color, roughly.

$colorA = B1B100 // original color
php code with little color engine lightening stuff up goes here
$colorB = ?????? // original color lightened up

Is there a php ready function that KNOWS rgb colors something like

php function RGB ( input color, what to do, output color) Where what to do could be +/- 255 values of brightness etc etc.

Is something like this already possible or am I day dreaming?

rgb-hsl($colorA, +10, $colorB);

If this does not exist, what would be the shortest code for doing this? Suggestions, code or ideas are all answers to me. Thanks.

like image 297
Sam Avatar asked Feb 23 '11 23:02

Sam


1 Answers

This SO question has a full-blown PHP script that can convert a RGB to a HSL colour, and increase its H component of a HSL colour - it should be trivial to change to increase L instead.

like image 102
Pekka Avatar answered Sep 28 '22 06:09

Pekka