note 44992 deleted from ref.image by tularis

From: Date: Sun, 29 Jun 2008 21:11:22 +0000
Subject: note 44992 deleted from ref.image by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140971@lists.php.net to get a copy of this message
Note Submitter: Henrik Nyh ---- I modified the gradient rectangle function by info [@] solanki [d o t] ch, to use hexadecimal colours instead of arrays. The hex-to-RGB code was taken from a comment by "tim at phantomrpg dot com" at http://se.php.net/manual/sv/function.imagecolorallocate.php <?php function imagecolorgradient($img,$x1,$y1,$x2,$y2,$f_c,$s_c){ sscanf($f_c, "%2x%2x%2x", $red, $green, $blue); $f_c = array($red,$green,$blue); sscanf($s_c, "%2x%2x%2x", $red, $green, $blue); $s_c = array($red,$green,$blue); 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; } ?> Usage example: <?php // Create a rectangle from 0,0 to 50,50 in $image, with a (vertical) gradient from #000000 to #FFFFFF. imagecolorgradient($image,0,0,50,50,'000000','FFFFFF'); ?>

« previous php.notes (#140971) next »