Pages

Faded Text

I actually converted an old JavaScript function to this PHP. I made a chat page and wanted a way to enhance the chat a bit. Then I remembered back in the AOL 4.0 days, we used to make chat faders. I couldn't find a PHP snippet that did such a task, so i set out to make one. This will convert your text's color. The string will start off as red, and fade to green (or what ever colors you want! View Demo



<? //simple to use!
// echo fadeText('ff0000','0000ff','this is the text that will be faded!');
function getColor($startc$endc$percentc)
{
$r1=hexdec(substr($startc,-6,2)); $g1=hexdec(substr($startc,-4,2)); $b1=hexdec(substr($startc,-2,2));
$r2=hexdec(substr($endc,-6,2)); $g2=hexdec(substr($endc,-4,2)); $b2=hexdec(substr($endc,-2,2));
$pcc $percentc/100;
$rcc= ($r1+($pcc*($r2-$r1)))*1; $gcc= ($g1+($pcc*($g2-$g1)))*1; $bcc= ($b1+($pcc*($b2-$b1)))*1; $frcdechex($rcc);  $fgcdechex($gcc);  $fbcdechex($bcc);

if (
strlen($frc)=="1"){ $frc="0".$frc;
}
if (
strlen($fgc)=="1"){ $fgc="0".$fgc;
}
if (
strlen($fbc)=="1"){ $fbc="0".$fbc;
}
$dasclr="#".$frc."".$fgc."".$fbc;
return 
$dasclr;
}

function 
fadeText($start$end$msg)
{
$myString2Fade $msg; $endResult=""; $daslen=strlen($myString2Fade);
for (
$i=$i<=$daslen $i++){ $perc=(100/$daslen)*$i;
if (
$myString2Fade[$i]==" "){ $endResult="$endResult ";
} else {
$endResult="$endResult<font color='".getColor($start$end$perc)."'>".$myString2Fade[$i]."</font>";
}
}
return 
$endResult;
}
?>

No comments:

Post a Comment