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

From: Date: Thu, 17 May 2007 13:33:16 +0000
Subject: Re: Confused about how exactly to output image using imagepng function
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-255055@lists.php.net to get a copy of this message
2007. 05. 17, csütörtök keltezéssel 14.49-kor Tijnema ! ezt írta: > On 5/17/07, Dave M G <martin@autotelic.com> 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 >

« previous php.general (#255055) next »