imagettftext() - 找不到字体位置

发布于 2024-12-27 05:01:31 字数 506 浏览 2 评论 0原文

我正在使用 imagettftext() 函数创建自定义验证码脚本。

我已在运行 PHP(版本 5.3.8)的 PC 上成功运行并测试了代码,但是当我上传到运行 PHP(版本 5.2.17)的共享托管帐户时,出现以下错误

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/pheelco/public_html/captcha.php on line 17

This is line 17;

imagettftext($img, 25, 0, 0, 25, $text, "fonts/alger.ttf", $num);

我肯定已经上传了带有该字体的文件夹“fonts”,它位于 public_html 文件夹中。

有什么想法吗?

注意:我无权更改任何 PHP 配置,因为我使用的是共享托管帐户。

I am using the imagettftext() function to create a custom captcha script.

I have ran and tested the code successfully on my PC, running PHP (Version 5.3.8) but when I upload to my shared hosting account running PHP (Version 5.2.17) it comes up with the following error

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/pheelco/public_html/captcha.php on line 17

This is line 17;

imagettftext($img, 25, 0, 0, 25, $text, "fonts/alger.ttf", $num);

I definitely have the folder "fonts" uploaded with that font, its in the public_html folder.

Any ideas?

Note: I don't have access to change any PHP configurations, as I'm using a shared hosting account.

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

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

发布评论

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

评论(2

素罗衫 2025-01-03 05:01:31

imagettftext 文档说:

字体文件

您要使用的 TrueType 字体的路径。

取决于 PHP 使用的 GD 库的版本,何时
字体文件不以前导 / 开头,则 .ttf 将被附加到
文件名和库将尝试搜索该文件名
沿着库定义的字体路径。

当使用低于2.0.18的GD库版本时,空格
字符而不是分号被用作“路径分隔符”
对于不同的字体文件。无意中使用此功能将
导致警告消息:警告:无法找到/打开字体。为了
对于这些受影响的版本,唯一的解决方案是将字体移动到
不包含空格的路径。

在许多情况下,字体与脚本位于同一目录中
使用下面的技巧将缓解任何包含问题。


你尝试过这个吗?您可以使用 gd_info 来检查您正在使用哪个版本的 GD。

The imagettftext documentation says:

fontfile

The path to the TrueType font you wish to use.

Depending on which version of the GD library PHP is using, when
fontfile does not begin with a leading / then .ttf will be appended to
the filename and the library will attempt to search for that filename
along a library-defined font path.

When using versions of the GD library lower than 2.0.18, a space
character, rather than a semicolon, was used as the 'path separator'
for different font files. Unintentional use of this feature will
result in the warning message: Warning: Could not find/open font. For
these affected versions, the only solution is moving the font to a
path which does not contain spaces.

In many cases where a font resides in the same directory as the script
using it the following trick will alleviate any include problems.

<?php // Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont'; ?>

Did you try this? You can use gd_info to check which version of GD you are working with.

稚气少女 2025-01-03 05:01:31

解决了。事实证明,文件名是“alger.TTF”,文件扩展名大写,在我的代码中,我用小写扩展名引用它。由于某种原因,这在 PHP 5.3.8 中仍然有效,但在 PHP 5.2.17 中无效,我希望这可以帮助遇到此问题的其他人

Solved. It turned out the file name was "alger.TTF" with a capitalised file extension and in my code I was referring to it with a lower-case extension. For some reason this still worked in PHP 5.3.8 but not in PHP 5.2.17 I hope this helps anybody else that comes across this issue

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