<?php

/*
 * gradtext.php4
 *
 * HTML font-gradient effect for PHP3/PHP4.
 * Given a pair of RGB values, and a string, provides a copy of that
 * string with <font> tags inserted so the letters change evenly in
 * color from starting to ending RGB.
 *
 * A very simple trick, but it looks pleasant.
 *
 * synopsis: gradtext(fromRed,fromGreen,fromBlue,
 *                    toRed,toGreen,toBlue,
 *                    string)
 *
 * Returns the apropriately fontified string.  If the string "rand" is
 * supplied instead of an integer value, it will be replaced with a random
 * integer in the range [0,255].
 *
 * Examples: echo gradtext(0,0,0,0xff,0x7f,0xff,"A string")
 *           echo gradtext(0,0,0,"rand","rand","rand","Rainbow")
 *          
 * by Devin Carraway <gradtext-box@devin.com>; also available in C,
 *    from http://www.devin.com/gradtext/
 *
 * Released under terms of the GNU General Public License,
 * http://www.gnu.org/copyleft/gpl.html
 *
 */

function gradtext($fr,$fg,$fb,$tr,$tg,$tb,$str)
{
    
$sl strlen($str);
    
$outstr "";

    if (!
$sl)
        return 
"";
    if (
$fr == "rand")
        
$fr rand(0,0xff);
    if (
$fg == "rand")
        
$fg rand(0,0xff);
    if (
$fb == "rand")
        
$fb rand(0,0xff);
    if (
$tr == "rand")
        
$tr rand(0,0xff);
    if (
$tg == "rand")
        
$tg rand(0,0xff);
    if (
$tb == "rand")
        
$tb == rand(0,0xff);
    for (
$i=0$i<$sl$i++) {
        if (
$str[$i] == " ") {
            
$outstr .= " ";
            
next;
        }
        
$pc $i/$sl;
        
$R abs($tr-$fr) * $pc
        
$G abs($tg-$fg) * $pc;
        
$B abs($tg-$fg) * $pc;
        
$outstr .= sprintf("<font color=\"#%02x%02x%02x\">%s</font>",
                    
$R,$G,$B,$str[$i]);
    }
    return 
$outstr;
}

?>