您的位置:首页 > 运维架构

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

2013-09-23 02:20 288 查看
在运行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以下版本的小缺陷吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php gd imagettfbbox
相关文章推荐