Well, the answer to your question is pretty simple, you cannot dump binary data directly into a web document. So you actually have to create two documents to dynamically generate an image with PHP and include that image in an HTML document.
The first document must be a normal HTML document.
Code:
<html>
<head>
</head>
<body>
<img src='image_emulator.php' alt='PHP image emulator.'/>
</body>
</html>
Then in a *second* document, write up your PHP that generates the image.
Code:
<?php
//image_emulator.php
header ('content-type: image/png')
$image = imagecreate(200, 200);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $black);
imagepng($image);
imagedestroy($image);
?>
This script does what its name implies, it emulates an image, it's just like creating a real .png file. By sending out the content-type header, the browser knows to treat the subsequent binary data as a PNG image, even though it really comes from a PHP script.
When you create this script, no whitespace can appear before the opening <?php delimiter, and no other output can come from the script, otherwise that data will get botched and the browser won't know what to do with it and you'll find yourself with a broken image.
Ever open up an image with a plain text editor?? This is what you see:
"@@@y^gls;tfjuw%$@y
That's the raw data of the image itself.
In the future you can verify the installation of PHP extenstions by running a phpinfo() script.
Code:
<?php
phpinfo();
?>
When you install GD, a new heading appears with information specific to that extension.
Regards,
Rich
--
[
http://www.smilingsouls.net]
[
http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail