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…

I suspect its not working because your probably wearing red socks instead of green.

I can confirm this after youve posted some CODE

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

OK, that looks OK.

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. :smiley:

why is this commented out?
//header (“Content-type: image/png”);

If your calling the image from an <img> tag you dont need the header. :wink:

The OP would also have gotten a ‘headers sent’ error, as the session_start would have already sent headers.

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)