I’m trying to create a CAPTCHA image as a form field using the GD Graphics library in PHP. The PHP functions used are:
imagecreatetruecolor();
imagecolorallocate();
imagefilledrectangle();
imageline();
imagesetpixel();
imagestring();
imagepng();
imagedestroy();
I’m getting the image, pixels, and lines, as well as the background color, but not the text. The code is below
mark
[php]session_start();
define(‘CAPTCHA_NUMCHRS’, 6);
define(‘CAPTCHA_WIDTH’, 100);
define(‘CAPTCHA_HEIGHT’, 25);
$passPhrase = ‘’;
for ($i = 0; $i < CAPTCHA_NUMCHRS; $i++)
{
$passPhrase .= chr(rand(97, 122));
}
$_SESSION[‘passPhrase’] = sha1($passPhrase);
$img = imagecreatetruecolor(CAPTCHA_WIDTH, CAPTCHA_HEIGHT);
$bgColor = imagecolorallocate($img, 255, 255, 255);
$textColor = imagecolorallocate($img, 0, 0, 0);
$graphicColor = imagecolorallocate($img, 64, 64, 64);
imagefilledrectangle($img, 0, 0, CAPTCHA_WIDTH, CAPTCHA_HEIGHT, $bgColor);
for ($i = 0; $i < 5; $i++)
{
imageline($img, 0, rand() % CAPTCHA_HEIGHT, CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphicColor);
}
for ($i = 0; $i < 50; $i++)
{
imagesetpixel($img, rand() % CAPTCHA_WIDTH, rand() % CAPTCHA_HEIGHT, $graphicColor);
}
imagestring($img, 3, 75, 75, $passPhrase, $textColor);
header(“Content-type: image/png”);
imagepng($img);
imagedestroy($img);[/php]