为什么 imagettftext 不起作用?

发布于 2024-08-23 10:40:24 字数 790 浏览 11 评论 0原文

我的“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--”(包括喜欢的文件)。

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

I have problems with the "imagettftext" function. The following code works if I comment the problematic line (I see a yellow rectangle).

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);

But if I uncomment the problematic line (to show some text) I get a problem. Mozilla writes me "The image cannot be displayed, because it contains errors".

May be this is related with the access to my font file (LucidaSansRegular.ttf). All files in my directory have "-rw-r--r--" (including the fond file).

Any suggestions? I need to add that on another server this code worked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海似她心 2024-08-30 10:40:24

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

希望这能向您解释它为何有效;)

/ means the root directory
./ means the current directory
../ means the parent directory

Hope this explains to you why it worked ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文