imagettftext():找不到/打开字体错误消息 [英] imagettftext(): Could not find/open font error message
本文介绍了imagettftext():找不到/打开字体错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试读取表单中的验证码图片。
I'm trying to read a captcha image in a form.
以下是表单代码:
<form class="login" method="POST" action="">
<p class="title">Are you human?</p>
<div id="captchaimage">
<img src="generate.php">
</div>
<input type="text" name="scr" size="6" placeholder="Write what you see here" autofocus/>
<input class="submititon" type="submit" value="Submit" name="submit"></input>
</form>
这是 generate.php
文件:
<?php
session_start();
//header('Content-type: image/jpeg');
$text = $_SESSION['scr'];
$font_size = 26;
$image_width = 100;
$image_height = 40;
$image = imagecreate($image_width, $image_height);
imagecolorallocate($image,255,255,255);
$text_color = imagecolorallocate($image,0,0,0);
for($x=1;$x<=30;$x++){
$x1 = rand(1, 100);
$y1 = rand(1, 100);
$x2 = rand(1, 100);
$y2 = rand(1, 100);
imageline($image, $x1, $y1 ,$x2 ,$y2, $text_color);
}
imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.ttf', $text);
imagejpeg($image);
?>
如您所见,我已注释掉 header()
查看此页面返回什么错误。错误是这样的:
As you can see I have commented out the header()
to see what error this page returns. And the error is this:
警告:imagettftext():无法在第25行找到/打开字体
第25行:
imagettftext($image, $font_size, 0, 15, 30, $text_color, 'font.ttf', $text);
我不知道为什么会发生此错误,因为 font.ttf
文件正确放置在同一目录中。
I don't know why this error happens because the font.ttf
file is placed correctly in the same directory.
那么这里发生了什么事?!
So what is going on here guys ?!
推荐答案
基于
$image = Image::canvas(750, 300, '#f3f3f3');
$image->text($title, 375, 150, function($font) {
$font->file(realpath('fonts/font-file.ttf'));
$font->size(44);
$font->color('#ffffff');
$font->align('center');
$font->valign('center');
});
您只需要将字体文件添加到| public / fonts / font-file.ttf
You just need to add font file to | public/fonts/font-file.ttf
这篇关于imagettftext():找不到/打开字体错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文