SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image not showing?

    Hi all,
    I Have generated an image with some simple maths to verify the user...
    This image is created by using the
    imagecreate(),imagecolorallocate() functions...

    But it is not showing, when i include it in another page...
    But when i call it explicitly, it is showing the image. Why?

    Thanking you., for your help, regarding this...

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I suspect its not working because your probably wearing red socks instead of green.

    I can confirm this after youve posted some CODE
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Evangelist venkat6134's Avatar
    Join Date
    Jul 2010
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the code i used to generate an small image, asking the user, to enter the result... in the text box...

    <?php
    session_start();
    //imagecreate -- Create a new palette based image
    $img = imagecreate(80, 20);
    //displaying the random text on the captcha image
    $black = imagecolorallocate($img, 0, 0, 0);
    $numero = rand(1,9);
    $numero1 = rand(1,9);
    if($numero<5)
    {
    $number = $numero.' + '.$numero1.' =';
    $val=$numero+$numero1;
    }
    else
    {
    $number = $numero.' * '.$numero1.' =';
    $val=$numero*$numero1;
    }
    $_SESSION['check'] = ($val);
    $white = imagecolorallocate($img, 255, 255, 255);
    imagestring($img, 10, 8, 3, $number, $white);
    //header ("Content-type: image/png");
    imagepng($img);
    ?>

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, that looks OK.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are outputting the image directly to the browser by only using the first argument in imagepng() - that only works if the image is the only thing you want to send to the browser. if the image needs to appear inside an html document you will need to save it by specifying the filepath as the second argument, then including it in the document with an <img> tag
    aaron-fisher.com - PHP articles and more

  6. #6
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aamonkey View Post
    you are outputting the image directly to the browser by only using the first argument in imagepng() - that only works if the image is the only thing you want to send to the browser. if the image needs to appear inside an html document you will need to save it by specifying the filepath as the second argument, then including it in the document with an <img> tag

    mmmm, not quite true aamonkey

    you can save the GD script as a .php file then call that file in a standard <img> tag as the source.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  7. #7
    SitePoint Addict Kevinslair's Avatar
    Join Date
    Jul 2002
    Location
    Binghamton
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why is this commented out?
    //header ("Content-type: image/png");
    I PHP!

  8. #8
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kevinslair View Post
    why is this commented out?
    //header ("Content-type: image/png");
    If your calling the image from an <img> tag you dont need the header.

    The OP would also have gotten a 'headers sent' error, as the session_start would have already sent headers.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  9. #9
    SitePoint Guru
    Join Date
    Aug 2009
    Posts
    669
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've had this a few times using captcha that I got from the white had site.

    Turned out to be white space every time.

    EDIT: Or some other output (eg print or echo somewhere)
    I'll do anything to avoid working on my own code

    Are you using: if (isset($_POST['submit'])) ?
    IE has a bug and does not always send the value.


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
  •