$x1 || $y > $y1) { return false; } $s = array( hexdec(substr($start,0,2)), hexdec(substr($start,2,2)), hexdec(substr($start,4,2)) ); $e = array( hexdec(substr($end,0,2)), hexdec(substr($end,2,2)), hexdec(substr($end,4,2)) ); $steps = $y1 - $y; for($i = 0; $i < $steps; $i++) { $r = $s[0] - ((($s[0]-$e[0])/$steps)*$i); $g = $s[1] - ((($s[1]-$e[1])/$steps)*$i); $b = $s[2] - ((($s[2]-$e[2])/$steps)*$i); $color = imagecolorallocate($img,$r,$g,$b); imagefilledrectangle($img,$x,$y+$i,$x1,$y+$i+1,$color); } return true; } /* This will create a simple vertical linear gradient between the two colors. The process in which this works is fairly simple, but I will explain it below. 1.Check if Rectangle Positions are positive values. 2.Convert the End and Start hex color codes to a RGB array. 3.Figure the amount of steps for the gradient. Just the End Y minus the Starting Y positions. 4.We loop through each row for the set Y positions. 5.We convert the RGB arrays to the new color for that row in the gradient. We grab the single Color (red for instance). And then we minus that red value (0-255) against the starting red minus the ending red color. That value is then divided by the steps multipied by the row we are currently on. A simple expression for this is $red - ( ( ( $red - $red2) / $steps ) * $position). 6.We do the color conversion for the red, green, and blue values. 7.We draw a single height rectangle for that row using the color we created, and then loop again. Hopefully this will help you get started with gradients. Doing the same thing but horizontal is really simple, you just need to modify the $steps variable and the imagefilledrectangle function. Modifications For Horizontal Gradient 1 2 $steps = $x1 - $x; imagefilledrectangle($img,$x+$i,$y,$x1+$i+1,$y1,$color); */ /* Include the above function here */ $imgWidth = 300; $imgHeight = 150; $img = imagecreatetruecolor($imgWidth,$imgHeight); image_gradientrect($img,0,0,$imgWidth,$imgHeight,'ff0000','0000ff'); /* Show In Browser as Image */ header('Content-Type: image/png'); imagepng($img); /* Save as a File */ imagepng($img); /* Some Cleanup */ imagedestroy($img); ?>