+ Reply to Thread
Results 1 to 6 of 6

Thread: php gd image do not displayed properly

  1. #1
    fatpandahk99 is offline x10Hosting Member fatpandahk99 is an unknown quantity at this point
    Join Date
    Jul 2010
    Posts
    5

    php gd image do not displayed properly

    Hi! I am a newbie in here. I try to create a simple image using php gd (in a file called index.html in the public_html folder), but there is no image show up. I have a header in html code and change it afterwards. Here is the code:

    <html>
    <body>
    <?php

    $im=imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream');

    $text_color=imagecolorallocate($im, 233, 14, 91);
    imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);

    header("Content-type: image/png");

    imagepng($im);
    imagedestroy($im);
    ?>
    </body>
    </html>

    And here is the output:
    Warning: Cannot modify header information - headers already sent by (output started at /home/kimo/public_html/index.php:3) in /home/kimo/public_html/index.php on line 17
    ‰PNG IHDRx0nIDATX…”I Ei5Žpl{‚."YVm‚:H-38.…B!Q ”|m`—j…^›|3Œrˆ:‡œ‡ +šGr:”_hZ*&_jil{65O%Ž<_V • œiFKE?‘2hs:`GaFӁ9˧^=[/;mk 8mW&+”ij%(s(ˆ~+›E„B!y"™IENDB`‚

    Could anyone let me know what I did wrong?
    Last edited by fatpandahk99; 07-09-2010 at 10:30 PM.

  2. #2
    dlukin is offline x10 Lieutenant dlukin is on a distinguished road
    Join Date
    Oct 2009
    Posts
    427

    Re: php gd image do not displayed properly

    1. Next time use "Go Advanced" and put your code either in PHP or CODE tags

    2. Post all the code. It is complaining about line 17 and you don't have that many lines.

  3. #3
    bhupendra2895's Avatar
    bhupendra2895 is offline x10 Elder bhupendra2895 is an unknown quantity at this point
    Join Date
    Jun 2010
    Location
    India
    Posts
    554

    Re: php gd image do not displayed properly

    Hi, Nothing should be sent before header header() even a white space is not allowed and use exit() after you sent header to user, so script will terminate.
    Last edited by bhupendra2895; 07-10-2010 at 01:41 AM.
    Liked this? Click on the icon on the bottom of post to make me .

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: php gd image do not displayed properly

    Ask yourself: why are you outputting HTML elements in an image? Remove the <html> and <body> tags. That particular error has been covered many times before on these very forums.
    Last edited by misson; 07-10-2010 at 04:00 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  5. #5
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: php gd image do not displayed properly

    For the sake of closing this issue, this is what Misson is suggesting:
    PHP Code:
    <?php
    header
    ("Content-type: image/png");
    $im=imagecreatetruecolor(12020) or die('Cannot Initialize new GD image stream');
    $text_color=imagecolorallocate($im2331491);
    imagestring($im155,  'A Simple Text String'$text_color);
    imagepng($im);
    imagedestroy($im);
    ?>
    Last edited by lemon-tree; 07-10-2010 at 10:37 AM.

  6. #6
    fatpandahk99 is offline x10Hosting Member fatpandahk99 is an unknown quantity at this point
    Join Date
    Jul 2010
    Posts
    5

    Re: php gd image do not displayed properly

    Thank you for the replies from Mission and Lemon-tree. I have been searching around for solution on that, but I found nothing. Thanks again.

+ Reply to Thread

Similar Threads

  1. MySQL Problem & cPanel not displayed properly
    By pikachu71396 in forum Free Hosting
    Replies: 2
    Last Post: 02-23-2010, 06:45 AM
  2. Big Image Small Image.
    By Parsa44 in forum Graphics & Webdesign
    Replies: 4
    Last Post: 03-09-2009, 02:40 AM
  3. Add-On Domain and Page is not displayed properly!
    By littlejumbo in forum Free Hosting
    Replies: 0
    Last Post: 11-14-2008, 12:02 AM
  4. Ads not displayed
    By GamingX in forum Free Hosting
    Replies: 0
    Last Post: 09-19-2007, 10:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers