为什么 imagettftext 不起作用?
我的“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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
/ 表示根目录
./ 表示当前目录
../ 表示父目录
希望这能向您解释它为何有效;)
/ means the root directory
./ means the current directory
../ means the parent directory
Hope this explains to you why it worked ;)