Voting

: three plus one?
(Example: nine)

The Note You're Voting On

slepichev at yahoo dot com
17 years ago
If you would like to change the intensity or lightness level of a specific color, you will need to convert the color format from RGB to HSL.
following function convert RGB array(red,green,blue) to HSL array(hue, saturation, lightness)
<?php
/**
* Convert RGB colors array into HSL array
*
* @param array $ RGB colors set
* @return array HSL set
*/
function rgb2hsl($rgb){

$clrR = ($rgb[0] / 255);
$clrG = ($rgb[1] / 255);
$clrB = ($rgb[2] / 255);

$clrMin = min($clrR, $clrG, $clrB);
$clrMax = max($clrR, $clrG, $clrB);
$deltaMax = $clrMax - $clrMin;

$L = ($clrMax + $clrMin) / 2;

if (
0 == $deltaMax){
$H = 0;
$S = 0;
}
else{
if (
0.5 > $L){
$S = $deltaMax / ($clrMax + $clrMin);
}
else{
$S = $deltaMax / (2 - $clrMax - $clrMin);
}
$deltaR = ((($clrMax - $clrR) / 6) + ($deltaMax / 2)) / $deltaMax;
$deltaG = ((($clrMax - $clrG) / 6) + ($deltaMax / 2)) / $deltaMax;
$deltaB = ((($clrMax - $clrB) / 6) + ($deltaMax / 2)) / $deltaMax;
if (
$clrR == $clrMax){
$H = $deltaB - $deltaG;
}
else if (
$clrG == $clrMax){
$H = (1 / 3) + $deltaR - $deltaB;
}
else if (
$clrB == $clrMax){
$H = (2 / 3) + $deltaG - $deltaR;
}
if (
0 > $H) $H += 1;
if (
1 < $H) $H -= 1;
}
return array(
$H, $S, $L);
}
?>

<< Back to user notes page

To Top