SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Image Problems

Hybrid View

  1. #1
    SitePoint Member Albertstine's Avatar
    Join Date
    Nov 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image Problems

    I am trying to use the gd libraries to create a basic image but am having some problems. I am using apache/1.3.22 with PHP/4.0.6. I have uncommented the php_gd.dll extension in the php.ini file and restarted apache. To ensure that gd was compiled I used the phpinfo() function to check. Gd is now enabled.

    I am using the following code to create the image:

    <?php

    Header("Content-Type image/png");
    $im = ImageCreate(500, 75);
    $red = ImageColorAllocate($im, 255,0,0);
    ImageFill($im, 100, 100, $red);
    ImagePNG($im);

    ?>

    The first problem that I noticed is that the ImagePNG()funtion is not highlighted in the editor.

    When I run the script the following warning is dislayed:

    Warning: Cannot add header information - header already sent by(output started at c:\program files\apache\group\apache\htdocs\test6.php:2) in C:\program files\apache group\apache\htdocs\test6.php on line 4

    Looking at this I think that the header has already been included. So I commented out the Header() function. This removed the warning but still the image was not displayed, only garbage text.

    I have spent some time looking for a solution to this problem but have had no luck. Any help on this topic would be gratefully appreciated.

    Thanks in advance

    Albertstine

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try putting a colon after "Content-type" in the header. e.g.

    PHP Code:
    header('Content-Type: image/png'); 
    if that doesn't work, make sure you don't have ANY whitespace before you send that header.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Member Albertstine's Avatar
    Join Date
    Nov 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help DR_LaRRY_PEpPeR, I tried your suggestions but still the same problems. I think that I am going to have to do a bit more research to try and find the solution.

    Once Again thanks

    Albertstine

  4. #4
    SitePoint Member Albertstine's Avatar
    Join Date
    Nov 2001
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem solved

    OK, this took me a while but I have finally found the solution. You can not have any blank lines above the <?php tag in the file that the image script is in. Otherwise the above error is generated.

    As an example:

    "won't work"
    VERY TOP OF PAGE
    (blank line)
    <?php

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

    ?>

    "will work"
    VERY TOP OF PAGE
    <?php

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

    ?>

    I am not sure if that is what DR_LaRRY_PEpPeR ment in the above but the browser will now display images.

    Once again thanks DR_LaRRY_PEpPeR for the help, it sent me in the right direction.

    Albertsitne

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Problem solved

    Originally posted by Albertstine
    I am not sure if that is what DR_LaRRY_PEpPeR ment in the above but the browser will now display images.
    yes, that's what i meant. hence the "ANY whitespace" in my post. gotta watch out for that. glad it's working now.

  6. #6
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Content-type is a header.
    Headers can't have anything sent to the browser before the header is sent.
    and if theres a line or space or anything else before the <?php or <? call, then the browser is getting sent that space and won't allow headers to be sent.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •