为什么 imagettfbbox() 无法读取第 y 行 x 中的字体?

Why could imagettfbbox() not read font in x on line y?

测试:

<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
?>
<pre>
<?php
//putenv('GDFONTPATH=' . realpath('.'));
print_r(gd_info());
echo 'phpuser: ' . get_current_user() . PHP_EOL;
echo 'scriptuser: ' . getmyuid() . PHP_EOL;
echo 'scriptgroup: ' . getmygid() . PHP_EOL;
$files = glob('captcha/fonts/*.ttf');
foreach ($files as $file) {
    echo 'file: ' . $file . PHP_EOL;
    echo 'fullpath: ' . __DIR__ . '/' . $file . PHP_EOL;
    echo 'chmod: ' . decoct(fileperms($file) & 0777) . PHP_EOL;
    echo 'fileowner: ' . fileowner($file) . PHP_EOL;
    echo 'user: ' . print_r(posix_getpwuid(fileowner($file)), true);
    echo 'filegroup: ' . filegroup($file) . PHP_EOL;
    echo 'group: ' . print_r(posix_getgrgid(filegroup($file)), true);
    echo 'isfile: ' . (is_file($file) ? 'yes' : 'no') . PHP_EOL;
    echo 'readable: ' . (is_readable($file) ? 'yes' : 'no') . PHP_EOL;
    echo 'writeable: ' . (is_writeable($file) ? 'yes' : 'no') . PHP_EOL;
    $size = mt_rand(10, 20);
    $angle = mt_rand(-35, 30);
    echo 'imagettfbbox with ' . $file . ':';
    imagettfbbox($size, $angle, $file, 'a');
    echo 'imagettfbbox with ' . str_replace('.ttf', '', $file) . ':';
    imagettfbbox($size, $angle, str_replace('.ttf', '', $file), 'a');
    echo 'imagettfbbox with ' . __DIR__ . '/' . $file . ':';
    imagettfbbox($size, $angle, __DIR__ . '/' . $file, 'b');
    echo PHP_EOL;
}
?>

结果:

Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 1
    [FreeType Linkage] => with freetype
    [T1Lib Support] => 1
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 1
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 1
    [XBM Support] => 1
    [JIS-mapped Japanese Font Support] => 
)
phpuser: user1
scriptuser: 825
scriptgroup: 820
file: captcha/fonts/assimila.ttf
fullpath: /home/.../captcha/fonts/assimila.ttf
chmod: 644
fileowner: 825
user: Array
(
    [name] => user1
    [passwd] => x
    [uid] => 825
    [gid] => 820
    [gecos] => 
    [dir] => /home/user1
    [shell] => /bin/bash
)
filegroup: 820
group: Array
(
    [name] => user1
    [passwd] => x
    [members] => Array
        (
            [0] => user1
        )

    [gid] => 820
)
isfile: yes
readable: yes
writeable: yes
imagettfbbox with captcha/fonts/assimila.ttf:
Warning:  imagettfbbox(): Could not read font in /home/.../test.php on line 27

imagettfbbox with captcha/fonts/assimila:
Warning:  imagettfbbox(): Could not read font in /home/.../test.php on line 29

imagettfbbox with /home/.../captcha/fonts/assimila.ttf:
Warning:  imagettfbbox(): Could not read font in /home/.../test.php on line 31

如您所见,我测试了这些问题的所有答案,但它们没有帮助:

也许是关于 GDFONTPATH 的有趣信息。如果我将它设置为:

putenv('GDFONTPATH=' . realpath('.') . '/captcha/fonts/');

然后错误消息显示 Could not find/open 而不是 Could not read :

Warning:  imagettfbbox(): Could not find/open font in /home/.../test.php on line 27

因此,我认为设置 GDFONTPATH 无法解决问题。

P.S。服务器正在使用 PHP 版本 5.5.38 和 LiteSpeed V6.10

问题已通过重新上传字体文件解决。它们是通过 Filezilla 以 ASCII 模式而不是正确的二进制模式上传的。这样字体文件就损坏了。

P.S。我没有设置 GDFONTPATH,它可以毫无问题地处理所有这些路径:

captcha/fonts/assimila.ttf
captcha/fonts/assimila
/home/{Userpath}/captcha/fonts/assimila.ttf