Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/gd/tests/gh17373.phpt fails without freetype support in gd #17891

Closed
orlitzky opened this issue Feb 22, 2025 · 5 comments
Closed

ext/gd/tests/gh17373.phpt fails without freetype support in gd #17891

orlitzky opened this issue Feb 22, 2025 · 5 comments

Comments

@orlitzky
Copy link
Contributor

Description

The new test in ext/gd/tests/gh17373.phpt can fail if gd (bundled or otherwise) does not have freetype support:

---- EXPECTED OUTPUT
int(0)
---- ACTUAL OUTPUT
Fatal error: Uncaught Error: Call to undefined function imagefttext() in /home/mjo/src/php-src.git/ext/gd/tests/gh17373.php:7
Stack trace:
#0 {main}
  thrown in /home/mjo/src/php-src.git/ext/gd/tests/gh17373.php on line 7
---- FAILED

For the bundled gd, there is the constant HAVE_GD_FREETYPE, but from config.m4 I infer that it probably only works with the bundled gd. Fixing it for the system gd is going to be a headache, because (much like png, webp, etc) libgd defines the associated freetype functions whether they work or not. For example,

#ifndef HAVE_LIBFREETYPE
...
BGD_DECLARE(char *) gdImageStringFT (gdImagePtr im, int *brect, int fg, const char *fontlist,
                                     double ptsize, double angle, int x, int y, const char *string)
{
	(void)im;
	(void)brect;
	(void)fg;
        (void)fontlist;
        (void)ptsize;
	(void)angle;
	(void)x;
	(void)y;
        (void)string;

        return "libgd was not built with FreeType font support\n";
}

We already have one clever autoconf macro for a similar purpose (image format detection), but the naming scheme and return value are different in this case.

PHP Version

git head

Operating System

No response

@cmb69
Copy link
Member

cmb69 commented Feb 23, 2025

Wouldn't the following do:

--SKIPIF--
if (!function_exists("imagefttext")) die("skip no freetype support");

@orlitzky
Copy link
Contributor Author

orlitzky commented Feb 23, 2025 via email

@cmb69
Copy link
Member

cmb69 commented Feb 23, 2025

Sadly no: this skips the test even if a system gd with freetype support is being used.

Then there would be a bug in ext/gd. If there is freetype support in libgd, the ext/gd function imagefttext() should be defined. Oh:

php-src/ext/gd/config.m4

Lines 196 to 199 in 1fa15ab

PHP_CHECK_LIBRARY([gd], [gdFontCacheShutdown],
[AC_DEFINE([HAVE_GD_FREETYPE], [1])],
[],
[$GD_SHARED_LIBADD])

looks hackish. We should not check for gdFontCacheShutdown(), but rather whether gdImageStringFT() returns something rather different from libgd was not built with FreeType font support.

PS: a "proper" libgd.pc should reveal the available features.

@orlitzky
Copy link
Contributor Author

Hold on, I may just be lying. It's possible that gdFontCacheShutdown() is ifdef'd out much earlier in the file. I sat down to hack on this and have a growing suspicion that I did my earlier test while SSHed into my work PC.

@orlitzky
Copy link
Contributor Author

Confirmed. Con: I'm an idiot. Pro: There's no need to write any autoconf macros.

#17891 (comment) is all it takes. Near certain I queried my gd package on the wrong machine.

orlitzky added a commit to orlitzky/php-src that referenced this issue Feb 24, 2025
This test calls imagefttext(), which may not be available if libgd
was built without freetype support.

Closes phpGH-17891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants