Ok all, I have a question regarding the gd library in php. First, let me say that there is really no reason why I am doing this the way that I am. I was a little bored with doing homework and thought to myself, hey I wonder if I can put a background images into parts of a webpage using css pointing to php files. So I set out to answer the question that was burning away at me... :)
Anyways, here is the code I am using to create the background for the top of a web page, 120px high. The final png is made up of smaller 5px high pngs that have a slight color change, giving the final effect of a little fade, if you will....
[CODE=php]
header ("Content-type: image/png");
$bg = imagecreatetrue color(100, 120);
$back = imagepng($bg, "bg.png");
$back = imagecreatefrom png("bg.png");
$color = 232;
$x = 0;
while ($x < 120) {
$im = imagecreatetrue color(100, 5);
$fill = imagecoloralloc ate($im, 0, 0, $color);
imagefill($im, 0, 0, $fill);
imagepng($im, "add.png");
$one = imagecreatefrom png("add.png");
imagecopy($back , $one, 0, $x, 0, 0, 100, 10);
imagepng($back, "bg.png");
$x = $x + 5;
$color = $color + 1;
imagedestroy($i m);
imagedestroy($o ne);
}
imagepng($back) ;
imagedestroy($b ack);
imagedestroy($b g);
?>
[/CODE]
Now the problem I run into intermittently is that every so often when the page loads, it doesn't render all the lines into the final png correctly. The color gets messed up in the smaller image and then the messed up smaller image gets added into the final image having the wrong color.
Any thoughts on why this might be or what is causing this?
Anyways, here is the code I am using to create the background for the top of a web page, 120px high. The final png is made up of smaller 5px high pngs that have a slight color change, giving the final effect of a little fade, if you will....
[CODE=php]
header ("Content-type: image/png");
$bg = imagecreatetrue color(100, 120);
$back = imagepng($bg, "bg.png");
$back = imagecreatefrom png("bg.png");
$color = 232;
$x = 0;
while ($x < 120) {
$im = imagecreatetrue color(100, 5);
$fill = imagecoloralloc ate($im, 0, 0, $color);
imagefill($im, 0, 0, $fill);
imagepng($im, "add.png");
$one = imagecreatefrom png("add.png");
imagecopy($back , $one, 0, $x, 0, 0, 100, 10);
imagepng($back, "bg.png");
$x = $x + 5;
$color = $color + 1;
imagedestroy($i m);
imagedestroy($o ne);
}
imagepng($back) ;
imagedestroy($b ack);
imagedestroy($b g);
?>
[/CODE]
Now the problem I run into intermittently is that every so often when the page loads, it doesn't render all the lines into the final png correctly. The color gets messed up in the smaller image and then the messed up smaller image gets added into the final image having the wrong color.
Any thoughts on why this might be or what is causing this?
Comment