【发布时间】:2018-04-08 19:27:16
【问题描述】:
我正在尝试在图像上写入文本,但出现错误: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
【问题讨论】:
-
您的“我已经尝试过”... 示例:前两个无效(断引号)。您是否也尝试过使用前导斜杠...即
/var/www/..... -
您的“代码”位于哪个文件夹/文件中。
-
它适用于 /var/www/.....。谢谢你,辛巴。