我尝试在代码点火器中创建自己的captcha库,现在库在没有代码点火器的情况下工作正常,但是当我将它包含在代码点火器中时,它给出了这个消息
遇到PHP错误
严重性:警告
消息:imagettftext(): Invalid font filename
文件名:助手/cap_helper.php
行号:13
//now my cap_helper.php looks like this
header('Content-type: image/jpeg');
function create_image($fontfile)
{
echo $fontfile;
$text = rand(0,9999);
$font_size = 30;
$image_width = 200;
$image_height = 40;
$image = imagecreate($image_width,$image_height);
imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, $font_size, 0, 15, 30, $text_color, $fontfile, $text);
imagejpeg($image);
}
//controller file looks like this
function __construct()
{
parent::__construct();
$this->form_validation->set_error_delimiters('<div class="alert alert-danger">','</div>');
$this->load->model(array('welcome_model'));
$this->load->helper(array('cap'));
}
function testing()
{
echo '<img src="'.create_image(base_url().'assets/font.ttf').'"/>';
}
'现在我的font.ttf文件保存在appname/assets/font.ttf中我做错了什么?
试试下面的代码
function testing(){
echo '<img src="'.create_image(realpath('assets/font.ttf')).'"/>';
}
我猜你最好不要使用url来定位你的字体,而是使用绝对路径。就像这样:
function testing()
{
echo '<img src="'.create_image('/assets/font.ttf').'"/>';
}