0

Test:

<?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;
}
?>

Result:

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

As you can see I tested all the answers from these questions but they did not help:

Maybe an interesting info regarding GDFONTPATH. If I set it to:

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

Then the error message says Could not find/open instead of Could not read :

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

Because of that I do not think setting GDFONTPATH solves the issue.

P.S. The server is using PHP Version 5.5.38 and LiteSpeed V6.10

Community
  • 1
  • 1
mgutt
  • 5,867
  • 2
  • 50
  • 77
  • It sounds like you're setting `putenv('GDFONTPATH=' . realpath('.') . '/captcha/fonts/')` to a non-existent path. – Mike 'Pomax' Kamermans Mar 31 '17 at 16:32
  • You did not read my script. I tested it with a correct path, too (line 7). – mgutt Mar 31 '17 at 16:38
  • Line 7 is `//putenv('GDFONTPATH=' . realpath('.'));` which doesn't really do much, but even if uncommented doesn't give me any indications that you're using the proper path. Can you update your post to explain the filesystem layout (which files are in which dirs) so we can have an idea of what your pathing will actually do? (ideally, you don't write that out by hand but get it from a dir structure readout, because your fingers can type what you think the layout should be, missing things like extra or fewer letters in path names etc.) – Mike 'Pomax' Kamermans Mar 31 '17 at 16:52

1 Answers1

1

The problem was solved by re-uploading the font files. They were uploaded through Filezilla in ASCII mode instead of the correct Binary mode. By that the font files became corrupt.

P.S. I did not set GDFONTPATH and it works with all those paths without problems:

captcha/fonts/assimila.ttf
captcha/fonts/assimila
/home/{Userpath}/captcha/fonts/assimila.ttf
mgutt
  • 5,867
  • 2
  • 50
  • 77
  • This also solved my problem. My code was working fine for years and then all of the sudden they stopped. It was the font file being corrupted. I re-uploaded the font (binary mode) and now it works! Thanks for this. – JasonC Jun 14 '17 at 12:59