I've a .ttf
file to be loaded to a captcha image. But my .ttf
just doesn't work. When I include a.ttf
file, the image does not load and gives an error.
Here's my captcha code:
<?php
session_start();
$md5_hash = md5(rand(0,999));
$captcha = substr($md5_hash, 16, 5);
$_SESSION["captcha"] = $captcha;
$width = 205;
$height = 60;
$image = imagecreate($width, $height);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$grey = imagecolorallocate($image, 204, 204, 204);
imagefill($image, 0, 0, $white);
$font = imageloadfont('Xeron.ttf');
imagestring($image, $font, 70, 20, $captcha, $black);
imagerectangle($image, 0, 0, $width-1, $height-1, $grey);
imageline($image, 0, $height/2, $width, $height/2, $grey);
imageline($image, $width/2, 0, $width/2, $height, $grey);
header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
?>
I'm new to php, Help please..
Edit
I've even tried it with the following code and still my image doesn't load
$captcha_num = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz';
$captcha_num = substr(str_shuffle($captcha_num), 0, 6);
$_SESSION["code"] = $captcha_num;
$font_size = 30;
$img_width = 70;
$img_height = 40;
header('Content-type: image/jpeg');
$image = imagecreate($img_width, $img_height); // create background image with dimensions
imagecolorallocate($image, 255, 255, 255); // set background color
$text_color = imagecolorallocate($image, 0, 0, 0); // set captcha text color
imagettftext($image, $font_size, 0, 15, 30, $text_color, 'Xeron.ttf', $captcha_num);
imagejpeg($image);