我正在尝试在图像上写入文本,但收到错误: 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
发布于 2018-01-04 13:08:54
你必须给出阅读字体的绝对路径。
所以给出如下字体路径:
$font = "/var/www/html/anti-bot/arial.ttf";请注意var之前的/,它从根目录获取路径
https://stackoverflow.com/questions/46970829
复制相似问题