I am currently programming a background-image using PHP with a color gradient for all browsers that do not support CSS3. I have got the following code:
<?php
header("Content-Type: image/png");
$from=array("R"=>255, "G"=>255, "B"=>255);
$to=array("R"=>170, "G"=>221, "B"=>255);
$width=500;
$height=1000;
$image=imagecreate($width, $height);
for($y=0; $y < $height; $y++)
{
imageline($image, 0, $y, $width, $y, imagecolorallocate($image, $from["R"]-(($from["R"]-$to["R"])/$height)*$y, $from["G"]-(($from["G"]-$to["G"])/$height)*$y, $from["B"]-(($from["B"]-$to["B"])/$height)*$y));
}
imagepng($image);
?>
It seems to be so simple but I really do not know why the image is not displayed correctly. It is shown as you can see below but the gradient should be 1000px high.

I could solve the problem. The function “imagecolorallocate” seems to be restricted to a limited number of calls. I used “imagecolorresolve” instead and it works fine. Another option is using “imagecreatetruecolor” for creating the image. Then you can use “imagecolorallocate”.