Page 1 of 1
image creation?
Posted: Mon Jun 06, 2005 11:12 pm
by asi0917
Code: Select all
<?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...
Re: image creation?
Posted: Tue Jun 07, 2005 1:17 am
by andre_c
assuming that
Code: Select all
<?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);
?>
and
Code: Select all
<img src="e;pic.png"e; border=0>
are on different files (which they should be), are you getting any errors?
actually if you name you php file image.php, the image tag should say
Code: Select all
<img src="e;image.php"e; />
next
Posted: Tue Jun 07, 2005 1:37 am
by asi0917
now im using this code:
Code: Select all
<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
Posted: Tue Jun 07, 2005 10:01 am
by pickle
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.
Posted: Tue Jun 07, 2005 11:26 am
by andre_c
like i said, it needs to be 2 files, one with the code, one with the markup
treat the code as if it IS the image
Posted: Tue Jun 07, 2005 2:36 pm
by pickle
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.
Posted: Tue Jun 07, 2005 3:00 pm
by andre_c
i guess i assumed he/she was doing the latter.
pickle is right