Random image generator only generates 2 pixels
The idea here is to generate a PNG image with each pixel a random color.
PHP Code:
<?php
header ('Content-type: image/png');
$width = $_GET['width'];
$height = $_GET['height'];
$image = @imagecreatetruecolor($width, $height)
or die('Cannot Initialize new GD image stream');
$x = 0;
$y = 0;
while ($y <= $height) {
while ($x <= $width) {
$red = rand(0,255);
$green = rand(0,255);
$blue = rand(0,255);
$color = imagecolorallocate($image,$red,$green,$blue);
imagesetpixel($image,$x,$y,$color);
$x = $x . 1;
}
$y = $y . 1;
}
imagepng($image);
imagedestroy($image);
?>
Unfortunately, only the upper-leftmost pixel and the one to the right of it are generated; the rest of the image remains black.
Why does this happen? (Live at http://thetortoise.tk/Untitled-3.php?width=50&height=50)