note 86198 added to function.imagecolorsforindex
| From: | hofstadler dot andi at gmx dot at | Date: | Tue, 07 Oct 2008 19:36:36 +0000 |
| Subject: | note 86198 added to function.imagecolorsforindex | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145136@lists.php.net to get a copy of this message | ||
I have optimized the rgb2hsl function from slepichev a bit, so that it is a bit shorter and
hopefully a bit faster:
<?php
/**
* Convert RGB colors array into HSL array
*
* @param array $ RGB colors set, each color component with range 0 to 255
* @return array HSL set, each color component with range 0 to 1
*/
function rgb2hsl($rgb){
$clrR = ($rgb[0]);
$clrG = ($rgb[1]);
$clrB = ($rgb[2]);
$clrMin = min($clrR, $clrG, $clrB);
$clrMax = max($clrR, $clrG, $clrB);
$deltaMax = $clrMax - $clrMin;
$L = ($clrMax + $clrMin) / 510;
if (0 == $deltaMax){
$H = 0;
$S = 0;
}
else{
if (0.5 > $L){
$S = $deltaMax / ($clrMax + $clrMin);
}
else{
$S = $deltaMax / (510 - $clrMax - $clrMin);
}
if ($clrMax == $clrR) {
$H = ($clrG - $clrB) / (6.0 * $deltaMax);
}
else if ($clrMax == $clrG) {
$H = 1/3 + ($clrB - $clrR) / (6.0 * $deltaMax);
}
else {
$H = 2 / 3 + ($clrR - $clrG) / (6.0 * $deltaMax);
}
if (0 > $H) $H += 1;
if (1 < $H) $H -= 1;
}
return array($H, $S,$L);
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 91.115.65.189
----
Manual Page -- http://www.php.net/manual/en/function.imagecolorsforindex.php
Edit -- https://master.php.net/note/edit/86198
Del: integrated -- https://master.php.net/note/delete/86198/integrated
Del: useless -- https://master.php.net/note/delete/86198/useless
Del: bad code -- https://master.php.net/note/delete/86198/bad+code
Del: spam -- https://master.php.net/note/delete/86198/spam
Del: non-english -- https://master.php.net/note/delete/86198/non-english
Del: in docs -- https://master.php.net/note/delete/86198/in+docs
Del: other reasons-- https://master.php.net/note/delete/86198
Reject -- https://master.php.net/note/reject/86198
Search -- https://master.php.net/manage/user-notes.php