TTFファイルを見つけることができませんが、何らかの理由で私は(ログファイルから)このエラーが出ます:PHPキャプチャは、私は自分のサイトにキャプチャを追加する必要が
:ここWarning: imagettfbbox(): Could not find/open font in /home/eric/www/captcha.php on line 24
Warning: imagettftext(): Could not find/open font in /home/eric/www/captcha.php on line 27
は私のコードです
function generate($width,$height,$characters='6') {
$code = '';
$availableChar = '23456789bcdfghjkmnpqrstvwxyz';
$i = 0;
while ($i < $characters) {
$code .= substr($availableChar, mt_rand(0, strlen($availableChar)-1), 1);
$i++;
}
$image = imagecreate($width, $height);
$text = imagecolorallocate($image, 20, 40, 100);
$things = imagecolorallocate($image, 100, 120, 180);
for($i=0; $i<($width*$height)/3; $i++) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $things);
}
for($i=0; $i<($width*$height)/150; $i++) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $things);
}
$textbox = imagettfbbox($height, 0, 'monofont.ttf', $code);
imagettftext($image, $height, 0, (($width - $textbox[4])/2), (($height - $textbox[5])/2), $text, 'monofont.ttf' , $code);
imagejpeg($image);
imagedestroy($image);
return $code;
}
header('Content-Type: image/jpeg');
$code = generate(100, 40, 5);
echo $_SESSION['security_code'] = $code;
と私のフォルダ内のファイル:
-rwxr-xr-x 1 tech4wilco tech4wilco 41036 1999-07-13 23:30 monofont.ttf
-rw-r--r-- 1 tech4wilco tech4wilco 1030 2011-10-17 15:43 captcha.php
私はいくつかの掘削を行なったし、どのような私が見つけたことは、フォントがあり、あなたはそれがSAMにあります見ることができるようにする必要がありますeフォルダをPHPファイルとして、私は何かを理解していないのですか?
エラーチェックは行われません。これらの関数(imagejpegなど)はすべてブール値やその成功を示すその他の情報を返します。それらの結果をキャッチし、どこが間違っているかを絞り込みます。 – GolezTrol
あなたが使用しているGDライブラリと関係があるかもしれません。 PHPのドキュメントから、 "PHPが使用しているGDライブラリのバージョンによっては、ファイル名に '.ttf'を追加し、ライブラリに沿って検索することで先頭に '/'を付けないファイルを検索しようとする場合があります定義されたフォントパス。おそらく、それはmonofont.ttf.ttfを探していましたか? –