繁体   English   中英

PHP无法找到/打开字体

[英]PHP Could not find/open font

我试图在图像上写文字,但我收到错误:PHP警告:imagettftext():无法在第12行的/var/www/html/anti-bot/image.php中找到/打开字体。

这是我的代码:

<?php
session_start();
header("Content-Type: image/png");
$text = rand(1000,1000000);
$_SESSION['code']=$text;
$img= imagecreatefromjpeg("bg.jpg");
$font = 'arial.ttf';
$R = rand(0,100);
$G = rand(0,100);
$B = rand(0,100);
$TxtColor = imagecolorallocate($img,$R,$G,$B);
imagettftext($img,rand(40,45),rand(0,1),rand(10,70),rand(38,50),$TxtColor,$font,$text);
imagepng($img);
imagedestroy($img);

?>

我努力了 :

$font = 'var/www/html/anti-bot/arial.ttf";
$font = 'var/www/html/anti-bot/arial";
$font = 'arial.ttf";
$font = 'arial";

所有文件都在同一目录下,var / www / html / anti-bot

你必须提供阅读字体的绝对路径。

所以给出如下字体路径:

$font = "/var/www/html/anti-bot/arial.ttf";

注意/var之前从根目录获取路径

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM