I'm not sure I understand quite how this works. For a website form I'd like to generate a random captcha image and display it along with the form. So ideally I would like something along those lines:
<form action="post.php" method="post">
...
<?php create_captcha(); ?>
</form>
While I do have a function which creates an image resource in PHP (link)
function create_captcha() {
$w = 60; $h = 30;
$img = imagecreatetruecolor($w, $h);
...
//header("Content-Type: image/jpeg");
imagejpeg($img);
}
I can't quite figure out how to output that image directly onto the website as part of the HTML form. My suspicion is that I'll have to save it into a temporary file captcha.jpg
and then generate a <img src="captcha.jpg" />
into the website.
Is there a more elegant way without using a temporary image?