+ Reply to Thread
Results 1 to 5 of 5

Thread: php gd image didn't show up

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

    php gd image didn't show up

    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 before and change it afterwards. Here is the code:

    HTML 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 9
    PNG  IHDRx0nIDATXI Ei5pl{."YVm:H-38.B!Q |m`j^|3r: +Gr:_hZ*&_jil{65O% <_V iF KE? 2hs:`GaFӁ9˧^=[/;mk 8mW&+ ij%(s(~+EЄB!y"IENDB`

    Could anyone let me know what I did wrong? Thank you!

  2. #2
    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 didn't show up

    You've already posted this question and got the correct response in your other thread.

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

    Re: php gd image didn't show up

    I tried exit(), and it doesn't work. And I put no space in front of header, that doesn't work either. Therefore, I posted again. Could anyone give me solution? Thank you.

    ---------- Post added at 05:07 PM ---------- Previous post was at 04:58 PM ----------

    lemon-tree: Thank you so much for your reply. I didn't get that before I reposted it. I got what Mission means and make it works. Thanks again. Sorry if the repost bothered you.

  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 didn't show up

    As long as you're dealing with the same problem, stick to the thread. If you don't understand a solution, you should ask for clarification in the same thread. If none of the offered solutions work, post this information in the same thread, along with how you applied the solutions and what the result was. If you haven't gotten a response that resolves your solution, and no-one has responded in a few days (a few hours isn't enough), bump the thread. Starting a duplicate thread is just spamming.

    If you're working on a new problem, then start a new thread.
    Last edited by misson; 07-10-2010 at 01:38 PM.
    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
    froger is offline x10Hosting Member froger is an unknown quantity at this point
    Join Date
    Sep 2009
    Posts
    49

    Re: php gd image didn't show up

    Quote Originally Posted by fatpandahk99 View Post
    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 before and change it afterwards. Here is the code:

    HTML 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 9
    ‰PNG IHDRx0nIDATX…”I Ei5Žpl{‚."YVm‚:H-38.…B!Q ”|m`—j…^›|3Œrˆ:‡œ‡ +šGr:”_hZ*&_jil{65O%Ž<_V • œiF KE?‘ 2hs:`GaFӁ9˧^=[/;mk 8mW&+ ”ij%(s(ˆ~+›E„B!y"™IENDB`‚

    Could anyone let me know what I did wrong? Thank you!
    You are trying to send a header after the headers have already been sent. You see header("Content-Type: image/png") needs to be set before the start <html> tagg.

    <?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);

    ?>
    should be lets say, image.php.

    By itself it will view the image because the pages content-type is image/png.

    If you want to place it into html though, you will have to create an <img> tag for image.php.

    Get it?
    Last edited by froger; 07-16-2010 at 10:25 PM.

+ Reply to Thread

Similar Threads

  1. Image files on website won't show!! Please help me!
    By emilyjolie in forum Graphics & Webdesign
    Replies: 9
    Last Post: 02-28-2010, 08:41 AM
  2. Big Image Small Image.
    By Parsa44 in forum Graphics & Webdesign
    Replies: 4
    Last Post: 03-09-2009, 02:40 AM
  3. Click on image map and show alert box???
    By goldy300 in forum Programming Help
    Replies: 1
    Last Post: 12-01-2008, 11:18 AM
  4. What Ads should I show
    By admbart in forum Free Hosting
    Replies: 1
    Last Post: 09-10-2008, 06:25 PM
  5. Can't get ads to show up!!!
    By nycdlmusckat in forum Free Hosting
    Replies: 11
    Last Post: 10-18-2005, 05:49 AM

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