【问题标题】:Why imagettftext does not work?为什么 imagettftext 不起作用?
【发布时间】:2010-03-03 13:14:15
【问题描述】:

“imagettftext”函数有问题。如果我注释有问题的行(我看到一个黄色矩形),则以下代码有效。

session_start();
$text = $_SESSION['code'];
header("Content-type: image/gif");
$image = imagecreate(150, 15);
$red_bg = 255; $green_bg = 255; $blue_bg = 155;
$bg_col = imagecolorallocate($image, $red_bg, $green_bg, $blue_bg);
$red_txt = 0; $green_txt = 0; $blue_txt = 0;
$text_col = imagecolorallocate($image, $red_txt, $green_txt, $blue_txt);
$font = "LucidaSansRegular.ttf";
$link_col = imagecolorallocate($image, 0, 0, 255);
//imagettftext($image, 10.0, 0.0, 5, 5, $text_col, $font, "aaaaa");
imagegif($image);

但是如果我取消注释有问题的行(以显示一些文本)我会遇到问题。 Mozilla 写信给我“图像无法显示,因为它包含错误”。

这可能与访问我的字体文件(LucidaSansRegular.ttf)有关。我目录中的所有文件都有“-rw-r--r--”(包括喜欢的文件)。

有什么建议吗?我需要在另一台服务器上添加此代码。

【问题讨论】:

  • 我有更多信息。我尝试从命令行运行代码,但得到“找不到/打开字体”。所以,我的假设是在正确的方向。但我还是不明白为什么。因为“组”和“其他”被允许读取这个文件。有什么问题?
  • 我解决了这个问题。在字体的文件名之前我需要放“./”。即:$font = "./LucidaBlaBlaBla.ttf"。有效。我不知道为什么,但它奏效了。
  • 你应该把你的最终解决方案写成“答案”然后接受它,这样这个问题就不会出现在“没有答案”中

标签: php image imagettftext


【解决方案1】:

/ 表示根目录 ./ 表示当前目录 ../ 表示父目录

希望这能向您解释它为什么起作用;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-07
    相关资源
    最近更新 更多