PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
header ("Content-type: image/png");
$im = @imagecreatetruecolor(50, 100)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im,"pic.png");
imagedestroy($im);
?>
<img src="pic.png" border=0>
is it my imagination that this code should output and image that is 50x100 with the text "a simple text string" in it?
it doesn't seem to work and its copied directly form the php.net manual except for the imagepng($im,"pic.png"); bit but ya, that shouldn't make it not work...
<html>
<body>
<?php
header ("Content-type: image/png");
$im = @imagecreatetruecolor(50, 100)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im,"image.php");
imagedestroy($im);
?>
<img src="image.php" />
</body>
</html>
with this error:
Error wrote:
Warning: Cannot modify header information - headers already sent by (output started at /home/freehost/t35.com/b/l/blkdragon96/image.php:3) in /home/freehost/t35.com/b/l/blkdragon96/image.php on line 4
That problem is because you've sent text already to the browser, before you call header(). However, you shouldn't need to call header() anyway. That function is used to send HTTP headers to the browser - it isn't necessary when creating an image.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Looking at it closer, there are other problems. Your code makes sense, but the logic is flawed. The code you showed tries to make a PNG image and save it in image.php. That shouldn't be how you do it.
There's really 2 ways to do what you want. You can have the image creation script run once and store it's output in a graphic, then reference that graphic. Or you can do like ~andre_c said and make the image creation script masquerade as an image file. Either way, there's work to be done.
Last edited by pickle on Tue Jun 07, 2005 4:27 pm, edited 1 time in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.