php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75656 imagettfbbox fails to find my font
Submitted: 2017-12-08 19:04 UTC Modified: 2018-04-03 22:01 UTC
Votes:24
Avg. Score:4.0 ± 1.1
Reproduced:20 of 22 (90.9%)
Same Version:11 (55.0%)
Same OS:18 (90.0%)
From: momchil at bojinov dot info Assigned:
Status: Open Package: GD related
PHP Version: 7.1.12 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: momchil at bojinov dot info
New email:
PHP Version: OS:

 

 [2017-12-08 19:04 UTC] momchil at bojinov dot info
Description:
------------
Hello,

I have a small repo here:
https://github.com/bozhinov/pChart2.0-for-PHP7

I tested all of the code with PHP 7.1.11 x64 TS on a Windows 10 x64 machine
and all was fine

I then updated the php distribution to 7.1.12 x64 TS and started getting warnings:
arning: imagettftext(): Could not find/open font in X:\SVN\External\pChart-dev\pChart\pDraw.php on line 1117

I can solve it by calling the function with realpath($ttfpath) instead 

The process monitor says that it finds the font OK but then starts looking at the Windows fonts folder and fails because these fonts are not there

Please fix
Momchil

Test script:
---------------
To induce it, download the release 2.2.0
please PHP distribution in the root folder and call any of the examples
e.g. 

php.exe examples\example.cache.php

Expected result:
----------------
Nothing

Actual result:
--------------
Warning: imagettfbbox(): Could not find/open font in X:\SVN\External\pChart-dev\pChart\pDraw.php on line 4878

Warning: imagettftext(): Could not find/open font in X:\SVN\External\pChart-dev\pChart\pDraw.php on line 1117

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-09 23:45 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2017-12-09 23:45 UTC] cmb@php.net
This is a duplicate of bug #64823.
 [2017-12-19 08:42 UTC] matthew at bossprint dot com
I had same problem
PHP Warning:  imagettftext(): Could not find/open font in C:...
Script has not changed since Nov 2016
Font is in same folder as script

Reverted to 7.1.11 and all is working again.
 [2017-12-19 11:38 UTC] cmb@php.net
-Status: Duplicate +Status: Re-Opened
 [2017-12-19 11:38 UTC] cmb@php.net
Obviously, this is not a duplicate, since the error message is
different. And indeed, I can reproduce the broken behavior with
PHP 7.1.12 (nts), but not with PHP 7.1.11 (nts).
 [2017-12-19 15:49 UTC] cmb@php.net
Well, the most trivial reproduce script:

  <?php
  var_dump((bool) imagettfbbox(12, 0, 'arial', 'foo'));

This is supposed to print

  bool(true)

but may print

  bool(false)

I have not been able to reproduce bool(false) with a self-built
PHP, and debugging with the official php-7.1.12-nts-Win32-VC14-x64
shows erratic behavior, so I'm at a loss.
 [2017-12-19 15:49 UTC] cmb@php.net
-Assigned To: cmb +Assigned To:
 [2018-01-08 12:00 UTC] ab@php.net
-Status: Re-Opened +Status: Feedback
 [2018-01-08 12:00 UTC] ab@php.net
I was checking this and 7.1.12 NTS reproduces it with Christoph's code. However the current 7.1 tree doesn't reproduce it - same freetype version. Something must have changed. Could one please test a latest snapshot?

Thanks.
 [2018-04-03 22:01 UTC] cmb@php.net
-Status: Feedback +Status: Open
 [2018-04-03 22:01 UTC] cmb@php.net
> Could one please test a latest snapshot?

I just tested with php-7.1-nts-windows-vc14-x64-r37e1d7c and
php-7.1-ts-windows-vc14-x64-r37e1d7c (renamed php.ini-development
to php.ini; uncommented extension_dir and extension=php_gd2.dll).
The imagettfbbox() call fails in both cases.  However, the ZTS
version warns "Invalid font filename", and the NTS version "Could
not find/open font".  The ZTS failure is obviously caused by a
failing open_basedir check[1] (even though open_basedir is empty);
the NTS failure, however, by fontFetch() failing[2] (which is not
a libfreetype issue).

Using the absolute path (C:/Windows/Fonts/arial.ttf) instead lets
the script succeed (both ZTS and NTS).

Anyhow, the ZTS failure has already been filed as
<https://bugs.php.net/64823>, so we should concentrate on the NTS
issue here (even though the OP mentions it happened on TS).

[1] <https://github.com/php/php-src/blob/PHP-7.1.16/ext/gd/gd.c#L3917>
[2] <https://github.com/php/php-src/blob/PHP-7.1.16/ext/gd/libgd/gdft.c#L454>
 [2018-07-23 14:09 UTC] Kagome at ese-protect dot de
Hello,

I expierenced today the same Problem.
I wanted to upgrade from PHP 7.1.11 to 7.2.8.
After I detected the same Problem as the OP I tested until i found a Version that worked.
It was Version 7.1.11 ...

Only to make it clear: It is the compiled TS-Version I used from windows.php.net

I'm using a Windows Server 2k12R2 and Apache 2.4.33 as Webserver.

Is there any timeline when this bug will be fixed?
 [2018-09-21 10:21 UTC] rolandshin at yahoo dot gr
I also experienced this problem when I changed to PHP 7.2.8 from PHP 5.6.

Using a visforms component for joomla.
"imagettftext(): Could not find/open font in D:\home\site\wwwroot\components\com_visforms\captcha\securimage.php on line 1211"

Modifying secure.php and calling the ttf file with realpath() also solved the problem for me
 [2018-11-02 10:58 UTC] drajuang at gmail dot com
(My english is not well)

I have expierenced this issue today, and I found a workaround.

Description:
------------

My OS is Windows 10 *Chinese Traditional* and Web Server is IIS, when I changed PHP version from v7.0.29 to v7.1.23, I got this warning:

    Warning: imageftbbox(): Could not find/open font in D:\projects\中文路徑\vendor\dapphp\securimage\securimage.php on line 1952

If I switch back to PHP v7.0, no error happened.

My font real path ($ttfpath) is 'D:\projects\中文路徑\vendor\dapphp\securimage\AHGBold.ttf'.

I tried 'realpath($ttfpath)' but not working, finally I found a key point 'character encoding'.
So, I tried:

    $ttfpath = 'D:\projects\中文路徑\vendor\dapphp\securimage\AHGBold.ttf';
    $ttfpath = mb_convert_encoding($ttfpath, 'big5', 'utf-8');

It is working, no error happened.


Conclusion:
------------

If:
	'OS is Windows' && 'PHP 7.1+' && 'filepath contain non ASCII characters'
	
Try:
	convert filepath string encoding before you pass to GD imageftbbox() and imagettftext().
	
	
Note:
	Maybe GD Library called a Windows File system API but that don't accept UTF8 encoding?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC