Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP无法找到/打开字体_Php_Fonts - Fatal编程技术网

PHP无法找到/打开字体

PHP无法找到/打开字体,php,fonts,Php,Fonts,我试图在图像上写入文本,但出现错误: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"); $fo

我试图在图像上写入文本,但出现错误: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);

?>

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

您必须为读取字体提供绝对路径

因此,请给出如下字体路径:

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

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

关于您的“我已经尝试过”。。。示例:前两个无效(引号断开)。你也试过用前导斜杠。。。ie
/var/www/..
您的“代码”位于哪个文件夹/文件中。它与/var/www/。谢谢你,辛巴。
$font = "/var/www/html/anti-bot/arial.ttf";