当我显示验证码图像时,出现以下错误:-
警告 (2): imagettftext() [function.imagettftext]: 找不到/打开字体我已将字体文件保存在根目录下。
这是我的代码 -
$path = fullpath to site images folder
$imgname = 'noise.jpg';
$imgpath = $path.'/'.$imgname;
$captchatext = md5(time());
$captchatext = substr($captchatext, 0, 5);
$_SESSION['captchatext'] = $captchatext;
$im = imagecreatefromjpeg($imgpath);
$grey = imagecolorallocate($im, 128, 128, 128);
$font = site_root_directory_path/BIRTH_OF_A_HERO.ttf;
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = $_SESSION['captchatext'];
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);