Re: Confused about how exactly to output image using imagepng function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2007. 05. 17, csütörtök keltezéssel 14.49-kor Tijnema ! ezt írta:
> On 5/17/07, Dave M G <martin@xxxxxxxxxxxxx> wrote:
> > PHP list,
> >
> > I've looked at the manual entries for imagepng() and
> > imagecreatetruecolor() functions for helping me to create a temporary
> > image for a CAPTCHA system.
> >
> > However, I'm clearly messing up, as what I'm outputting is a bunch of
> > ASCII gibberish to the screen.
> >
> > What I think I need to do in principle is first create the image with
> > imagecreatetruecolor(), then define it as a PNG (?), then display it.
> >
> > So I've got something like this:
> >
> > $image = ImageCreate($width, $height);
> > ImageFill($image, 0, 0, $black);
> > echo '<img " src="' . Imagepng($image) . '" height="' . $height . '"
> > width="' . $width .'" alt="captcha" />' . "\n";
> > ImageDestroy($image);
> >
> > As mentioned, this isn't working, so there's a fundamental concept about
> > how PHP creates and displays images that I'm not getting.
> >
> > I'm trying to output an image that, ideally, won't be stored as a file.
> > Or, if it has to be a temporary file, to delete it immediately after
> > displaying it.
> >
> > What part am I not understanding?
> >
> > Thank you for any advice or information.
> >
> 
> It's quite simple, a second PHP script should generate the image, not
> the same as that isn't gonna work.
> 
> as src expects an url where the source is located, and what you are
> doing is that you're giving the source right there.
> 
> so you should have a second script called image.php or such with code:
> $image = ImageCreate($width, $height);
> ImageFill($image, 0, 0, $black);
> Imagepng($image);
> ImageDestroy($image);

don't forget to send proper content-type header before the image data

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

or something like that

greets
Zoltán Németh

> 
> and then in your first page like
> echo '<img " src="image.php" height="' . $height . '"
> width="' . $width .'" alt="captcha" />' . "\n";
> 
> 
> Tijnema
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux