Set a single pixel in PHP
Description
The following code shows how to set a single pixel.
Example
<?php//from w ww .j a v a 2 s. co m
$x = 400;
$y = 400;
$gd = imagecreatetruecolor($x, $y);
$corners[0] = array('x' => 100, 'y' => 10);
$corners[1] = array('x' => 0, 'y' => 390);
$corners[2] = array('x' => 400, 'y' => 390);
$red = imagecolorallocate($gd, 255, 0, 0);
for ($i = 0; $i < 100000; $i++) {
imagesetpixel($gd, round($x),round($y), $red);
$a = rand(0, 2);
$x = ($x + $corners[$a]['x']) / 2;
$y = ($y + $corners[$a]['y']) / 2;
}
header('Content-Type: image/png');
imagepng($gd);
?>
The code above generates the following result.