Hallo,
wenn ihr einen Farbverlauf in einem Text oder Div bereich Dynamisch erstellen wollt ist dieses Skript was für euch:
Für <DIV> bereiche:
$h=600; //Höhe des Farbverlaufes in Pixel
//Startfarbe im RGB Format
$r1 = 161; //R
$g1 = 161; //G
$b1 = 161; //B
//Endfarbe im RGB Format
$r2 = 255; //R
$g2 = 255; //G
$b2 = 255; //B
$s = array($r1,$g1,$b1);
$e = array($r2,$g2,$b2);
for ($i = 0; $i<$h; $i++) {
$c1 = max(0,$s[0]-((($e[0]-$s[0])/-$h)*$i));
$c2 = max(0,$s[1]-((($e[1]-$s[1])/-$h)*$i));
$c3 = max(0,$s[2]-((($e[2]-$s[2])/-$h)*$i));
echo "<div style=\"clear:left; font-size:0px; top:".$i."px; left:0px; height:1px; width:600px; border:0px; background-color:rgb(".round($c1,0 ).", ".round($c2, 0).", ".round($c3,0 ).");\"></div>\n";
}
Für Texte:
$TEXT="Hier ist dann belibiger Text !!";
//Startfarbe im RGB Format
$r1 = 161; //R
$g1 = 161; //G
$b1 = 161; //B
//Endfarbe im RGB Format
$r2 = 255; //R
$g2 = 255; //G
$b2 = 255; //B
$s = array($r1,$g1,$b1);
$e = array($r2,$g2,$b2);
$h=strlen($TEXT);
for ($i = 0; $i<$h; $i++) {
$c1 = max(0,$s[0]-((($e[0]-$s[0])/-$h)*$i));
$c2 = max(0,$s[1]-((($e[1]-$s[1])/-$h)*$i));
$c3 = max(0,$s[2]-((($e[2]-$s[2])/-$h)*$i));
$letter=$TEXT[$i];
echo "<font style=\"color:rgb(".round($c1,0 ).", ".round($c2, 0).", ".round($c3,0 ).");\">$letter</font>";
}
Solltet ihr jetzt noch vorhaben mehrere Farbverläufe zu erstellen verwendet diesen Code:
function farbverlauf($TEXT)
{
$farben = array (
"[P1]"=>"196,0,5,255,204,205",
"[P2]"=>"210,0,205,255,193,254",
);
while (list ($key, $val) = each ($farben)) {
if(strpos(" ".$TEXT,$key)) {
$TEXT=str_replace($key,"",$TEXT);
if(!$DO)
{
list($r1,$g1,$b1,$r2,$g2,$b2) = split("[,]",$val);
$DO="1";
}
}
}
$s = array($r1,$g1,$b1);
$e = array($r2,$g2,$b2);
if($DO)
{
$h=strlen($TEXT);
for ($i = 0; $i<$h; $i++) {
$c1 = max(0,$s[0]-((($e[0]-$s[0])/-$h)*$i));
$c2 = max(0,$s[1]-((($e[1]-$s[1])/-$h)*$i));
$c3 = max(0,$s[2]-((($e[2]-$s[2])/-$h)*$i));
$buchstabe=$TEXT[$i];
$new_TEXT.="<font style=\"color:rgb(".round($c1,0 ).", ".round($c2, 0).", ".round($c3,0 ).");\">$buchstabe</font>";
}
}else{
$new_TEXT=$TEXT;
}
return$new_TEXT;
}
$TEXT="[P1]Mein Text";
echo farbverlauf($TEXT);
Der Letzte Code ersetzt [P1] durch den Farbverlauf !
Achtung es kann nur 1 Farbverlauf Pro $TEXT ausgeführt werden !
mfg Stefan