note 44992 added to ref.image

From: Date: Sun, 22 Aug 2004 19:05:08 +0000
Subject: note 44992 added to ref.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-75125@lists.php.net to get a copy of this message
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'); ?> ---- Manual Page -- http://www.php.net/manual/en/ref.image.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+44992 Delete -- http://master.php.net/manage/user-notes.php?action=delete+44992&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+44992&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#75125) next »