Re: How to create an image on the fly?



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

.



Relevant Pages

  • Re: [PHP] generating an html intro text ...
    ... > html and htmlentities that may be part of the content. ... > original string: ... HTML special characters ... echo $str."\n"; ...
    (php.general)
  • Secure feedback form
    ... Now I have rewrite the feedback form. ... I am not using echo in functions anymore. ... I use return $html instead. ... user can select to "edit" the information" and will then find ...
    (alt.php)
  • Re: Script Need to check disk space on remote servers
    ... You might find this easier using WMIC (PowerShell would be even easier). ... A command like this will check one computer, myComputer and create a simple HTML table with the name, size and freespace. ... echo Checking drives on Server %%S... ... REM and then launches it using the default browser. ...
    (microsoft.public.windows.server.scripting)
  • Re: Getting ID from a presented table
    ... Jerry Stuckle ... JDS Computer Training Corp. ... Same idea - just generated with a PHP echo statement instead. ... I do not know how to do that in HTML. ...
    (comp.lang.php)
  • Re: Repost: Conditional look-ahead?
    ... Well Gunnar, believe it! ... not studied any of the HTML 'modules' as I don't class the issue as an HTML ... that would close a tag based on the non-presence of said tag. ... > Steve Dunn wrote: ...
    (comp.lang.perl.misc)