By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,748 Members | 1,506 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,748 IT Pros & Developers. It's quick & easy.

How to create an image on the fly?

P: n/a
Hi.

I've created an image with this code

Header("Content-Type: image/png");
$image = ImageCreate($W,$H);
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);
ImageLine($image,0,0,$W,$H,$black);
ImagePng($image);
ImageDestroy($image);

but now I wish to add a line

echo "Hello";

before the image code, then I only get garbage, the header command is
probably invalid now. So how do I create the image without having to save
the image to a file?
Jan 30 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Gunnar G wrote:
Hi.

I've created an image with this code

Header("Content-Type: image/png");
$image = ImageCreate($W,$H);
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);
ImageLine($image,0,0,$W,$H,$black);
ImagePng($image);
ImageDestroy($image);

but now I wish to add a line

echo "Hello";

before the image code, then I only get garbage, the header command is
probably invalid now. So how do I create the image without having to save
the image to a file?
Hi Gunnar,

Your code should return html OR an image.
It cannot return both because they have different mimetypes.

So you need a script that returns html OR an image, not both.

A trick to debug your imagecreationscript is changing you
Header("Content-Type: image/png");
to
Header("Content-Type: text/html");

so you can see errors in your PHP-code.

Of course you'll have to put it back to the original when you think the
imagecreationscript runs fine.

Regards,
Erwin Moller

Jan 30 '07 #2

P: n/a
Rik
Gunnar G <de****@comhem.sewrote:
Hi.

I've created an image with this code

Header("Content-Type: image/png");
$image = ImageCreate($W,$H);
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);
ImageLine($image,0,0,$W,$H,$black);
ImagePng($image);
ImageDestroy($image);

but now I wish to add a line

echo "Hello";

before the image code, then I only get garbage, the header command is
probably invalid now. So how do I create the image without having to save
the image to a file?
Euhm, adding "hello" to the source of an image isn't really valid no :-)..

-----hello.html----
hello
<img src="imagecreator.php">
--------------------
---imagecreator.php-
//your php code
--------------------

--
Rik Wasmus
Jan 30 '07 #3

P: n/a
-----hello.html----
hello
<img src="imagecreator.php">
--------------------
---imagecreator.php-
//your php code
--------------------
Ah, great solution. thanks.
Jan 30 '07 #4

P: n/a
On Tue, 30 Jan 2007 07:13:03 -0800, Gunnar G <de****@comhem.sewrote:
Hi.

I've created an image with this code

Header("Content-Type: image/png");
$image = ImageCreate($W,$H);
$white = ImageColorAllocate($image,255,255,255);
$black = ImageColorAllocate($image,0,0,0);
ImageLine($image,0,0,$W,$H,$black);
ImagePng($image);
ImageDestroy($image);

but now I wish to add a line

echo "Hello";

before the image code, then I only get garbage, the header command is
probably invalid now. So how do I create the image without having to save
the image to a file?
Or just write the text using imagestring() or imagefttext/imagettftext;
this way, it's part of the image, not sure of that's what you want, though.

--
Curtis, http://dyersweb.com
Feb 1 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.