【问题标题】:PHP Could not find/open fontPHP 找不到/打开字体
【发布时间】: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/.....。谢谢你,辛巴。

标签: php fonts


【解决方案1】:

你必须给出阅读字体的绝对路径。

所以给字体路径如下:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多