<?
# функция градиента текста (переливание цвета)
function gradient($text, $hexfrom, $hexto){
$text = iconv('utf-8','windows-1251',$text);
$colorsteps = strlen($text);
$fromrgb['r'] = hexdec(substr($hexfrom, 0, 2));
$fromrgb['g'] = hexdec(substr($hexfrom, 2, 2));
$fromrgb['b'] = hexdec(substr($hexfrom, 4, 2));
$torgb['r'] = hexdec(substr($hexto, 0, 2));
$torgb['g'] = hexdec(substr($hexto, 2, 2));
$torgb['b'] = hexdec(substr($hexto, 4, 2));
$steprgb['r'] = ($fromrgb['r'] - $torgb['r']) / ($colorsteps - 1);
$steprgb['g'] = ($fromrgb['g'] - $torgb['g']) / ($colorsteps - 1);
$steprgb['b'] = ($fromrgb['b'] - $torgb['b']) / ($colorsteps - 1);
for($i = 0; $i <= $colorsteps; $i++){
$rgb['r'] = floor($fromrgb['r'] - ($steprgb['r'] * $i));
$rgb['g'] = floor($fromrgb['g'] - ($steprgb['g'] * $i));
$rgb['b'] = floor($fromrgb['b'] - ($steprgb['b'] * $i));
$hexrgb['r'] = sprintf('%02x', ($rgb['r']));
$hexrgb['g'] = sprintf('%02x', ($rgb['g']));
$hexrgb['b'] = sprintf('%02x', ($rgb['b']));
$color = implode(null, $hexrgb);
$return .= '<font color="'.$color.'">'.$text[$i].'</font>';
}
return iconv('windows-1251','utf-8',$return);
}
echo gradient('Супер пупер текст в градиенте','000000', 'FF0000'); // пример использования
?>
Изменил: KOZZ (11.12.2010 / 07:41)