Drawing lines

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I want to draw a line chart with PHP.  If I make my Draw() function the only
function call, it works fine.  But if I display other data, and then call my
Draw() function, I get a bunch of graphics characters, and some text.  The
text says I have already defined the header info.  Here is the ledgible part
of the text

Warning: Cannot modify header information - headers already sent by (output
started at /home/virtual/site8/fst/var/www/html/laps/laps.php:10) in
/home/virtual/site8/fst/var/www/html/laps/lib.php on line 498

Here is my Draw() function.  I just cut and pasted some code off a website.
I can't even draw a single line yet!

   function Draw()
  Header("Content-type: image/jpeg");
  $image = ImageCreate(200,150);
  $gray = ImageColorAllocate($image,204,204,204);
  $blue = ImageColorAllocate($image,0,0,255);

Any ideas why I cannot call the Header function here, or why my web page
just shows a bunch of text and graphic characters ?


Re: Drawing lines

Douglas Hay wrote:
Quoted text here. Click to load it

That's correct.  Headers must be sent BEFORE anything else is sent.

You're example will create a page with a single jpeg.  You can't have
any other content on the page.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Re: Drawing lines

Quoted text here. Click to load it

Make sure your <?php statement is the very start of the file.  Any white
space will count as HTML output.  Any HTML output sends the headers.

Stephen Oakes

Re: Drawing lines

Douglas Hay wrote:

Quoted text here. Click to load it


2 things I can think of:
1) Did you echo anything?
Like echo "myvar = $myvar";
This can also be caused by whitespaces before the script starts.

2) Maybe you made some error, and PHP spits it out.
So you are generating text (errormessages).

View the result of the image in a texteditor, and look for errorlines.

Good luck.

Erwin Moller

Re: Drawing lines

Douglas Hay wrote:
Quoted text here. Click to load it
If you have used echoe/print etc.. then headers are already sent.  To
get around this problem use two pages/php scripts.  The first is the
display file containing your formatting page stuff.  Somewhere in that
file you call the second script that creates the jpg, using <img
src="jpg-generating-php.php"> which is the script you alreay posted that
draws lines.  This second script does set the headers, but they are
expected in the image tag.

Good luck.

Re: Drawing lines

Thanks for all the help, Craig's suggestion worked great and I got it
working now.

Thanks to all of you!


Quoted text here. Click to load it
call my
Quoted text here. Click to load it

Site Timeline