PHP and GD

  • 18 years ago

    Can somebody suggest me what this error message means displayed in the browser with a lot of gobbled data when I try to run examples for generating images, "Cannot add header information - headers already sent by". GD is properly installed, I run check ups from the beginning of the tutorial and used examples given here. Many thanks.

  • 18 years ago

    can you post your source code? It sounds like what is happening is that some
    header() statements are after some binary/html data has been sent to the browser.

  • 18 years ago

    This is my first example, but as with all others I get pretty much the same result, which is that it doesn't work.


    <html>
    <head>
    </head>
    <body>
    <?php
    Header("Content-type: image/jpeg");
    $image = ImageCreate(200,150);
    $gray = ImageColorAllocate($image,204,204,204);
    $blue = ImageColorAllocate($image,0,0,255);
    ImageLine($image,10,10,150,30,$blue);
    ImageJPEG($image);
    ImageDestroy($image);
    ?>
    </body>
    </html>

  • 18 years ago

    the line

    Code:

    Header("Content-type: image/jpeg");


    has to be the very first line that is sent to the browser, so you need to get rid of :


    Code:

    <html>
    <head>
    </head>
    <body>


    and i would suggest that you get rid of:

    Code:

    </body>
    </html>


    aswell.


    have a look at http://www.php.net/manual/en/features.images.php for more information and an example of how to use the code in another php page.

  • 18 years ago

    Thank you very much, everything works perfectly. I relly didn't now that PHP code shouldn't be inserted into the HTML when working with images.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There's no test like production” - Anon