I'm trying, for reasons best known to my unconscious mind, to generate a snow-crash-like picture.
Using PHP5 and GD v2.0 (or higher), I'm using the following php/html:
<?php
$x = $y = 100;
$gd = imagecreatetruecolor($x,$y);
$w = imagecolorallocate($gd, 255, 255, 255);
$b = imagecolorallocate($gd, 0, 0, 0);
for ($r=1; $r <= $y; $r++) {
for ($c=1; $c <= $x; $c++) {
if (rand(0,1) == 0) {
$rand = $w;
}
else {
$rand = $b;
}
imagesetpixel($gd,$r,$c,$rand);
}
}
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
</head>
<body page="snowcrash2">
<?php
echo "<div id=\"snowcrashimg\">";
header('Content-Type: image/png');
imagepng($gd);
echo "</div>";
?>
</body>
</html>
I was trying to iterate over each 'column' of each 'row' of the image, setting the pixel value to either 1 or 0 to reflect either black or white.
However, this throws the (fun) error: "Warning: Cannot modify header information - headers already sent by (output started at /var/www/play/snowcrash2.php:32) in /var/www/play/snowcrash2.php on line 51"
Moving the header(...) to the first couple lines of the (in an attempt to put the header somewhere that it might get sent in time) leads to the following error (in image form): the image "http://127.0.0.1/play/snowcrash2.php" cannot be displayed, because it contains errors."
Umm...help?
The only other topic that came up is this one Generated image using PHP and GD is being cut off, which has no accepted answer and isn't, so far as I can see, relevant to the problem I'm having.