php - 使用带有 imagettftext 的字体时出现问题

标签 php fonts gd

这是我在更改有效网站的环境时收到的错误消息:

Warning: imagettftext() [function.imagettftext]: Could not find/open font 

首先我以为这是由于缺乏文件权限,但事实并非如此,我检查了路径并将所有文件设置在 777 中... 然后我检查GD,看起来它已经安装了:

GD Support  enabled
GD Version  bundled (2.0.34 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.3.5
GIF Read Support    enabled
GIF Create Support  enabled
JPG Support     enabled
PNG Support     enabled
WBMP Support    enabled
XBM Support     enabled 

我正在尝试使用 arial.ttf,所以我猜没有太多异国情调...... 知道从哪里开始看吗?

谢谢

最佳答案

如果您使用的字体与脚本位于同一目录中(开头没有前导 /),请仅键入 arial,不带 .ttf。如果它在另一个目录中,则必须包含 .ttf。顺便说一句:如果您可以添加您正在使用的代码,那就太好了。

这里是示例代码:

# Correct
$font = 'arial'; 

# Wrong
$font = 'arial.ttf';


# Correct
$font = '/fonts/arial.ttf';

# Wrong
$font = '/fonts/arial';

PHP.NET说:

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.

关于php - 使用带有 imagettftext 的字体时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5566236/

相关文章:

php - 通过php更新数据库中的数据

php - imagecreatefromstring() : gd-jpeg, libjpeg:可恢复错误:JPEG 文件过早结束

php - Symfony2 : Spaces in image when using GD

php - 从 PHP 调用时外部 JS 不工作创建 HTML

php - 用于动态显示 WooCommerce 产品类别的嵌套短代码

php - smarty 调试控制台

PHP - 确定给定字体中是否存在字形

css - Chrome 中的连字 : Only displaying when adding other characters

fonts - Arial Black-Websafe字体?

php - 向图像添加空格并将文件保存到服务器