javier Posted May 21, 2006 Share Posted May 21, 2006 Hello, I've been working with a script to display certain information from my game's characters over a png rectangle, something like this:|Info here|The thing is, I'd like to color it with a vertical gradient, but I haven't been able to do so.I got this code off some webiste (might be outdated..?):[code]function imagecolorgradient($img, $hv, $x1, $y1, $x2, $y2, $f_c, $s_c) { // Modified version of code by info@solanki.ch taken from php.net // posted: 14-Feb-2004 07:43 // $img is the image handle. // $hv is either horizontal 'h' or vertical 'v' gradient. // $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. if ($hv == 'v') { $y = ($y2 > $y1) ? $y2-$y1 : $y1-$y2; } else { $x = ($x2 > $x1) ? $x2-$x1 : $x1-$x2; } $r_range = ($f_c[0] > $s_c[0]) ? $f_c[0] - $s_c[0] : $s_c[0] - $f_c[0]; $g_range = ($f_c[1] > $s_c[1]) ? $f_c[1] - $s_c[1] : $s_c[1] - $f_c[1]; $b_range = ($f_c[2] > $s_c[2]) ? $f_c[2] - $s_c[2] : $s_c[2] - $f_c[2]; if ($hv == 'v') { $r_px=$r_range/$y; $g_px=$g_range/$y; $b_px=$b_range/$y; $xy = $y; } else { $r_px=$r_range/$x; $g_px=$g_range/$x; $b_px=$b_range/$x; $xy = $x; } $r=$f_c[0]; $g=$f_c[1]; $b=$f_c[2]; for($i=0;$i<=$xy;$i++) { $col=imagecolorallocate($img,round($r),round($g),round($b)); if ($hv == 'v') { imageline($img,$x1,$y1+$i,$x2,$y1+$i,$col); } else { imageline($img,$x1+$i,$y1,$x1+$i,$y2,$col); } $r = ($f_c[0] < $s_c[0]) ? $r + $r_px : $r - $r_px; $g = ($f_c[1] < $s_c[1]) ? $g + $g_px : $g - $g_px; $b = ($f_c[2] < $s_c[2]) ? $b + $b_px : $b - $b_px; } return $img; } [/code]The thing is, I don't know how to create the gradient off that code. I tried the following:[code]imagecolorgradient($myImage, 1, 20, ($iWidth-2), ($iHeight-2), $dkblue, $blue); // where$myImage = imagecreate($iWidth, $iHeight);//and $blue, $dk blue are rgb colors[/code]That's about it.Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/10138-image-creation-png/ Share on other sites More sharing options...
litebearer Posted May 21, 2006 Share Posted May 21, 2006 Might look here...[a href=\"http://www.poirrier.be/~jean-etienne/info/clibs/gd-rainbow.php\" target=\"_blank\"]http://www.poirrier.be/~jean-etienne/info/.../gd-rainbow.php[/a]or[a href=\"http://frenchfragfactory.net/ozh/my-projects/images-php-gd-gradient-fill/\" target=\"_blank\"]http://frenchfragfactory.net/ozh/my-projec...-gradient-fill/[/a]or[a href=\"http://www.php-editors.com/contest/1/68-read.html\" target=\"_blank\"]http://www.php-editors.com/contest/1/68-read.html[/a]Lite... Quote Link to comment https://forums.phpfreaks.com/topic/10138-image-creation-png/#findComment-37780 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.