Farbverlauf in PHP

Moin HaBo,

ich habe auch mal wieder ein problem. Ich hoffe, dass mir diesmal geholfen werden kann... Ich will eine kleine FUNCTION in php schreiben, die in der lage ist einen Verlauf in einer tabelle zu erstellen (horizontal). Ein beispiel für einen vertikalen verlauf habe ich hier: http://boppy.dyn.ee/index2/pisg

- Allerdings ist das obrige Script in Perl verfasst (es handelt sich um PiSG) und ich verstehe absolut gar nichts von PERL. Der Code-Part ist dieser hier: http://boppy.dyn.ee/narf.txt

Wie stelle ich es nun an in PHP einen genau so guten farbverlauf zu erstellen??



Wäre echt super dankbar, wenn mir einer von euch helfen könnte...

Edit: hier nochmal ganz deutlich: http://boppy.dyn.ee/habo_intern/blau_grau
 
PHP:
function SeparateRBG($col) 
{ 
$Color[R]= hexdec(substr($col, 0, 2 )); 
$Color[B] = hexdec(substr($col, 2, 2)); 
$Color[G] = hexdec(substr($col, -2)); 

return $Color ; 
} 


function Gradient($coldeb, $colfin, $n) 
{ 
$Color[deb] = SeparateRBG($coldeb); 
$Color[fin] = SeparateRBG($colfin); 
$rbg = array('R', 'B', 'G'); 


foreach ($rbg as $RBG) 
{ 
  $Color[enc][$RBG] = floor( (($Color[fin][$RBG]) - ($Color[deb][$RBG])) / $n ); 
  for ($x = 0 ; $x < $n ; $x++) 
  { 
   $Color[gradient][$RBG][$x] = dechex($Color[deb][$RBG] + ($Color[enc][$RBG] * $x)); 
   if (strlen(strval($Color[gradient][$RBG][$x])) < 2) 
   { 
    $Color[gradient][$RBG][$x] = '0' . $Color[gradient][$RBG][$x]; 
   } 
  } 
} 

for ($i = 0 ; $i < $n ; $i++) 
{ 
  $GradientColor[] = $Color[gradient][R][$i] . $Color[gradient][B][$i] . $Color[gradient][G][$i]; 
} 
return $GradientColor; 
}

Beispiel:
$coldeb = Startfarbe
$colfin = Zielfarbe
PHP:
include('gradient_function.php');
$coldeb = '99FF99'; 
$colfin = 'CCFFFF'; 
$n = 79; 
echo '<table cellpadding=0 cellspacing=0 border=0 width=100%>'; 
foreach (Gradient($coldeb, $colfin, $n) as $gr) 
{ 
 echo '<tr bgcolor="#' . $gr . '"><td>col</td><td>col2</td></tr>'; 
 } 
echo '</table>';
 
Zurück
Oben