The problem arises when the php page changes its content type. All php pages have ads embedded in them, so the resulting image would be messed up with the ad text mixed in with the image data. I couldn't get it to work like it should.
But I did find a bit of a workaround. What you do is basically the same, except you write the image to a separate file, and then redirect from the php page that just created that image to the image file itself.
For example:
<?php
$msg="MTE says ".$_SERVER['REMOTE_ADDR'];
$font=2;
$margin=1;
$height = imagefontheight($font) + 2 * $margin;
$width = imagefontwidth($font) * strlen($msg) + 2 * $margin;
$image = ImageCreate($width, $height);
$bgcolor = ImageColorAllocate($image, 31, 5, 5);
$fgcolor = ImageColorAllocate($image, 255, 255, 255);
ImageFilledRectangle($image, 0, 0, $width, $height, $bgcolor);
ImageString($image, $font, $margin, $margin, $msg, $fgcolor);
// output the image
if (function_exists("imagepng")) {
imagepng($image, "temp.png");
header('Location: temp.png');
} elseif (function_exists("imagejpeg")) {
imagejpeg($image, "temp.jpg", 0.5);
header('Location: temp.jpg');
} else {
die("No image support in this PHP server");
}
?>
See it in action here:
http://chickenmeister.t35.com/temp/examplehtmlpagewithimage.htmlhope this is of some help.
