note 39893 deleted from ref.image by tularis
| From: | tularis@php.net | Date: | Sun, 29 Jun 2008 21:11:46 +0000 |
| Subject: | note 39893 deleted from ref.image by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-140975@lists.php.net to get a copy of this message | ||
Note Submitter: info [@] solanki [d o t] ch
----
A quite important function missing in the gdlib ist the color gradient.
After trying a bit I got one that works quite good.
So if anybody needs it:
<?php
function imagecolorgradient($img,$x1,$y1,$x2,$y2,$f_c,$s_c){
if($y2>$y1) $y=$y2-$y1;
else $y=$y1-$y2;
if($f_c[0]>$s_c[0]) $r_range=$f_c[0]-$s_c[0];
else $r_range=$s_c[0]-$f_c[0];
if($f_c[1]>$s_c[1]) $g_range=$f_c[1]-$s_c[1];
else $g_range=$s_c[1]-$f_c[1];
if($f_c[2]>$s_c[2]) $b_range=$f_c[2]-$s_c[2];
else $b_range=$s_c[2]-$f_c[2];
$r_px=$r_range/$y;
$g_px=$g_range/$y;
$b_px=$b_range/$y;
$r=$f_c[0];
$g=$f_c[1];
$b=$f_c[2];
for($i=0;$i<=$y;$i++){
$col=imagecolorallocate($img,round($r),round($g),round($b));
imageline($img,$x1,$y1+$i,$x2,$y1+$i,$col);
if($f_c[0]<$s_c[0]) $r+=$r_px;
else $r-=$r_px;
if($f_c[1]<$s_c[1]) $g+=$g_px;
else $g-=$g_px;
if($f_c[2]<$s_c[2]) $b+=$b_px;
else $b-=$b_px;
}
return $img;
}
?>
$img ist the image handle, $x1 and $y1 are the start points, $x2 and $y2 the ending points.
$f_c and $s_c are the first and second color ARRAYs.