首页  编辑  

PHP Captcha can't find the TTF file, ThinkPHP验证码错误

Tags: /PHP/   Date Created:
PHP Captcha can't find the TTF file
Warning: imagettfbbox(): Could not find/open font in
windows下如果ThinkPHP或者其他PHP代码中,调用imagettfbbox出现Could not find/open font in 错误。而明显对应的字体文件是存在的,那么是中文路径的问题。
解决方法:
不要使用中文路径名
或者:

修改php.ini,添加一行:
extension=php_mbstring
记得确保 php_mbstring.dll 文件保存在PHP的相应目录下。
然后在代码中,先把中文路径名转成utf8,再传给imagettftext即可:
$font_path = mb_convert_encoding(realpath(中文路径名.ttf), "GB2312", "utf-8");
imagettftext($this->_image, $this->fontSize, mt_rand(-40, 40), $codeNX, $this->fontSize * 1.6, $this->_color, $font_path, $code[$i]);