GD Warning: imagettfbbox(): Could not find/open font

在运行pChart的example的时候出现了这个问题,字体路径是没问题的,代码应该也无问题。网上找了一下,发现官网有相应的提示:http://php.net/manual/en/function.imagettftext.php

 

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 appendedto 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';
?>
 

遇到这个问题可能的原因是字体路径中出现了“.”,不巧的是,我的脚本就出现了。

 

这个问题的解决方案有两个:

第一种:就是按官网所说的,在使用imagettfbbox()函数前设置GDFONTPATH环境变量;

第二种:我发现使用字体的绝对路径,也是能够加载的。

 

网上有说法是linux不能用相对路径,这是错误的,算是GD2.0.18以下版本的小缺陷吧。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值