06-02-2009, 02:16 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: May 2009
Location: lagos, nigeria
Posts: 13
Thanks: 9
|
Captcha image isn't showing
php Code:
session_start(); //-------------------- // CAPTCHA Function //-------------------- function captcha ($length = 6) { $length = isset($_GET[ 'chars'] ) ? $_GET[ 'chars'] : 6; // Let's generate a totally random string using md5 $hash = md5(rand(0, 999)); // We don't need a 32 character long string so we trim it down to 5 $code = substr($hash, 15, $length); // Set the session to store the security code $_SESSION[ "captcha"] = $code; // Set the image width and height $width = 200; $height = 50; // Create the image resource $image = imagecreate ($width, $height); // Random RGB colours $rgb1 = rand(0, 255); $rgb2 = rand(0, 255); $rgb3 = rand(0, 255); $background = imagecolorallocate ($image, $rgb1, $rgb2, $rgb3); $text = imagecolorallocate ($image, ($rgb1 - 50), ($rgb2 - 50), ($rgb3 - 50)); // Make the background colour imagefill ($image, 0, 0, $background); // Add randomly generated string in the image for($i = 1; $i <= $length; $i++ ) { $counter = rand(1, 2); if ($counter == 1) { $angle = rand(0, 45); } if ($counter == 2) { $angle = rand(315, 360); } /*problem*/ imagettftext ($image, rand(14, 20), $angle, ($i * 25), 30, $text, "templates/ChalkboardBold.ttf", substr($code, ($i - 1), 1)); } // Add a border imagerectangle ($image, 0, 0, $width - 1, $height - 1, $text); // Tell the browser what kind of file is come in header("Content-Type: image/png"); // Output the newly created image in jpeg format imagepng ($image); // Free up resources imagedestroy ($image); } ! isset($_GET[ 'chars'] ) ? captcha () : captcha ($_GET[ 'chars'] );
I got this code from this site but it shows this error in IE:
Quote:
Warning: imagettftext() [function.imagettftext]: Invalid font filename in C:\wamp\www\arrays\learningfiles.php on line 102
‰PNG IHDRÈ2#Ÿ¢PLTEÕš£hO¹¾„+IDATxœcø 040`Œ£2£2£2£2C\gÉ ÓIÿûáo«IEND®B`‚
|
I think the problem is from the line where I marked problem. How do I solve this, please?
Last edited by Wildhoney : 06-02-2009 at 03:35 PM.
|
|
|
|