Drawing lines

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Douglas Hay

    Drawing lines

    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!

    <?php
    function Draw()
    {
    Header("Content-type: image/jpeg");
    $image = ImageCreate(200 ,150);
    $gray = ImageColorAlloc ate($image,204, 204,204);
    $blue = ImageColorAlloc ate($image,0,0, 255);
    ImageLine($imag e,10,10,150,30, $blue);
    ImageJPEG($imag e);
    ImageDestroy($i mage);
    }?>

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

    Thanks,
    Doug


  • Stephen Oakes

    #2
    Re: Drawing lines


    "Douglas Hay" <xxx@xxx.com> wrote...[color=blue]
    > Any ideas why I cannot call the Header function here[/color]

    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


    Comment

    • Erwin Moller

      #3
      Re: Drawing lines

      Douglas Hay wrote:
      [color=blue]
      > 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[/color]

      Hi,

      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) .

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

      Good luck.

      Regards,
      Erwin Moller

      Comment

      • Jerry Stuckle

        #4
        Re: Drawing lines

        Douglas Hay wrote:[color=blue]
        > 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!
        >
        > <?php
        > function Draw()
        > {
        > Header("Content-type: image/jpeg");
        > $image = ImageCreate(200 ,150);
        > $gray = ImageColorAlloc ate($image,204, 204,204);
        > $blue = ImageColorAlloc ate($image,0,0, 255);
        > ImageLine($imag e,10,10,150,30, $blue);
        > ImageJPEG($imag e);
        > ImageDestroy($i mage);
        > }?>
        >
        > Any ideas why I cannot call the Header function here, or why my web page
        > just shows a bunch of text and graphic characters ?
        >
        > Thanks,
        > Doug
        >
        >[/color]
        Doug,

        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.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Craig Storey

          #5
          Re: Drawing lines

          Douglas Hay wrote:[color=blue]
          > 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!
          >
          > <?php
          > function Draw()
          > {
          > Header("Content-type: image/jpeg");
          > $image = ImageCreate(200 ,150);
          > $gray = ImageColorAlloc ate($image,204, 204,204);
          > $blue = ImageColorAlloc ate($image,0,0, 255);
          > ImageLine($imag e,10,10,150,30, $blue);
          > ImageJPEG($imag e);
          > ImageDestroy($i mage);
          > }?>
          >
          > Any ideas why I cannot call the Header function here, or why my web page
          > just shows a bunch of text and graphic characters ?
          >
          > Thanks,
          > Doug
          >
          >[/color]
          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.

          Comment

          • Douglas Hay

            #6
            Re: Drawing lines

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

            Thanks to all of you!

            Doug

            "Craig Storey" <crig.storey@nr c.ca> wrote in message
            news:d3h5rt$evr $1@nrc-news.nrc.ca...[color=blue]
            > Douglas Hay wrote:[color=green]
            > > I want to draw a line chart with PHP. If I make my Draw() function the[/color][/color]
            only[color=blue][color=green]
            > > function call, it works fine. But if I display other data, and then[/color][/color]
            call my[color=blue][color=green]
            > > Draw() function, I get a bunch of graphics characters, and some text.[/color][/color]
            The[color=blue][color=green]
            > > text says I have already defined the header info. Here is the ledgible[/color][/color]
            part[color=blue][color=green]
            > > of the text
            > >
            > > Warning: Cannot modify header information - headers already sent by[/color][/color]
            (output[color=blue][color=green]
            > > 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[/color][/color]
            website.[color=blue][color=green]
            > > I can't even draw a single line yet!
            > >
            > > <?php
            > > function Draw()
            > > {
            > > Header("Content-type: image/jpeg");
            > > $image = ImageCreate(200 ,150);
            > > $gray = ImageColorAlloc ate($image,204, 204,204);
            > > $blue = ImageColorAlloc ate($image,0,0, 255);
            > > ImageLine($imag e,10,10,150,30, $blue);
            > > ImageJPEG($imag e);
            > > ImageDestroy($i mage);
            > > }?>
            > >
            > > Any ideas why I cannot call the Header function here, or why my web page
            > > just shows a bunch of text and graphic characters ?
            > >
            > > Thanks,
            > > Doug
            > >
            > >[/color]
            > 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.[/color]


            Comment

            Working...