Skip to content

Update gd extension preprocessor macros help texts #15296

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

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 53 additions & 35 deletions ext/gd/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ AC_DEFUN([PHP_GD_PNG],[
PKG_CHECK_MODULES([PNG], [libpng])
PHP_EVAL_LIBLINE([$PNG_LIBS], [GD_SHARED_LIBADD])
PHP_EVAL_INCLINE([$PNG_CFLAGS])
AC_DEFINE(HAVE_LIBPNG, 1, [ ])
AC_DEFINE([HAVE_LIBPNG], [1], [Define to 1 if you have the libpng library.])
])

AC_DEFUN([PHP_GD_AVIF],[
if test "$PHP_AVIF" != "no"; then
PKG_CHECK_MODULES([AVIF], [libavif >= 0.8.2])
PHP_EVAL_LIBLINE([$AVIF_LIBS], [GD_SHARED_LIBADD])
PHP_EVAL_INCLINE([$AVIF_CFLAGS])
AC_DEFINE(HAVE_LIBAVIF, 1, [ ])
AC_DEFINE(HAVE_GD_AVIF, 1, [ ])
AC_DEFINE([HAVE_LIBAVIF], [1],
[Define to 1 if you have the libavif library.])
AC_DEFINE([HAVE_GD_AVIF], [1],
[Define to 1 if gd extension has AVIF support.])
fi
])

Expand All @@ -88,8 +90,10 @@ AC_DEFUN([PHP_GD_WEBP],[
PKG_CHECK_MODULES([WEBP], [libwebp >= 0.2.0])
PHP_EVAL_LIBLINE([$WEBP_LIBS], [GD_SHARED_LIBADD])
PHP_EVAL_INCLINE([$WEBP_CFLAGS])
AC_DEFINE(HAVE_LIBWEBP, 1, [ ])
AC_DEFINE(HAVE_GD_WEBP, 1, [ ])
AC_DEFINE([HAVE_LIBWEBP], [1],
[Define to 1 if you have the libwebp library.])
AC_DEFINE([HAVE_GD_WEBP], [1],
[Define to 1 if gd extension has WebP support.])
fi
])

Expand All @@ -98,8 +102,10 @@ AC_DEFUN([PHP_GD_JPEG],[
PKG_CHECK_MODULES([JPEG], [libjpeg])
PHP_EVAL_LIBLINE([$JPEG_LIBS], [GD_SHARED_LIBADD])
PHP_EVAL_INCLINE([$JPEG_CFLAGS])
AC_DEFINE(HAVE_LIBJPEG, 1, [ ])
AC_DEFINE(HAVE_GD_JPG, 1, [ ])
AC_DEFINE([HAVE_LIBJPEG], [1],
[Define to 1 if you have the libjpeg library.])
AC_DEFINE([HAVE_GD_JPG], [1],
[Define to 1 if gd extension has JPEG support.])
fi
])

Expand All @@ -108,8 +114,9 @@ AC_DEFUN([PHP_GD_XPM],[
PKG_CHECK_MODULES([XPM], [xpm])
PHP_EVAL_LIBLINE([$XPM_LIBS], [GD_SHARED_LIBADD])
PHP_EVAL_INCLINE([$XPM_CFLAGS])
AC_DEFINE(HAVE_XPM, 1, [ ])
AC_DEFINE(HAVE_GD_XPM, 1, [ ])
AC_DEFINE([HAVE_XPM], [1], [Define to 1 if you have the xpm library.])
AC_DEFINE([HAVE_GD_XPM], [1],
[Define to 1 if gd extension has XPM support.])
fi
])

Expand All @@ -119,27 +126,34 @@ AC_DEFUN([PHP_GD_FREETYPE2],[

PHP_EVAL_INCLINE([$FREETYPE2_CFLAGS])
PHP_EVAL_LIBLINE([$FREETYPE2_LIBS], [GD_SHARED_LIBADD])
AC_DEFINE(HAVE_LIBFREETYPE, 1, [ ])
AC_DEFINE(HAVE_GD_FREETYPE, 1, [ ])
AC_DEFINE([HAVE_LIBFREETYPE], [1],
[Define to 1 if you have the FreeType library.])
AC_DEFINE([HAVE_GD_FREETYPE], [1],
[Define to 1 if gd extension has FreeType support.])
fi
])

AC_DEFUN([PHP_GD_JISX0208],[
if test "$PHP_GD_JIS_CONV" = "yes"; then
AC_DEFINE(USE_GD_JISX0208, 1, [ ])
AC_DEFINE(JISX0208, 1, [ ])
AC_DEFINE([USE_GD_JISX0208], [1],
[Define to 1 if gd extension has JIS-mapped Japanese font support.])
AC_DEFINE([JISX0208], [1],
[Define to 1 if GD library has JIS-mapped Japanese font support.])
fi
])

dnl
dnl PHP_GD_CHECK_FORMAT(format, [action-if-found])
dnl
dnl Build and run a program to determine if GD has support for the given
dnl format. The first argument is the proper-noun-capitalized name of the
dnl format -- basically the word Foo in gdImageCreateFromFoo -- such as
dnl Png. If support for format Foo exists, the second argument (the name
dnl of a constant) will be defined to 1. The reason for this charade is
dnl that gd defines "junk" versions of each gdImageCreateFromFoo function
dnl even when it does not support the Foo format. Those junk functions
dnl display a warning but eventually return normally, making a simple link
dnl or run test insufficient.
dnl Png. If support for "format" Foo exists, the "action-if-found" is executed.
dnl The reason for this charade is that gd defines no-op versions of each
dnl gdImageCreateFromFoo function even when it does not support the Foo format.
dnl Those no-op functions display a warning but eventually return normally,
dnl making a simple link or run test insufficient.
dnl
AC_DEFUN([PHP_GD_CHECK_FORMAT],
[AS_VAR_PUSHDEF([php_var], [php_cv_lib_gd_gdImageCreateFrom$1])
old_LIBS="${LIBS}"
Expand Down Expand Up @@ -171,33 +185,34 @@ int main(int argc, char** argv) {
[AS_VAR_SET([php_var], [yes])],
[AS_VAR_SET([php_var], [no])],
[AS_VAR_SET([php_var], [no])])])
AS_VAR_IF([php_var], [yes],
[AC_DEFINE_UNQUOTED([$2], [1],
[Define to 1 if GD library has 'gdImageCreateFrom$1'.])])
AS_VAR_IF([php_var], [yes], [$2])
AC_LANG_POP([C])
CFLAGS="${old_CFLAGS}"
LIBS="${old_LIBS}"
AS_VAR_POPDEF([php_var])
])

AC_DEFUN([PHP_GD_CHECK_VERSION],[
PHP_GD_CHECK_FORMAT([Png], [HAVE_GD_PNG])
PHP_GD_CHECK_FORMAT([Avif], [HAVE_GD_AVIF])
PHP_GD_CHECK_FORMAT([Webp], [HAVE_GD_WEBP])
PHP_GD_CHECK_FORMAT([Jpeg], [HAVE_GD_JPG])
PHP_GD_CHECK_FORMAT([Xpm], [HAVE_GD_XPM])
PHP_GD_CHECK_FORMAT([Bmp], [HAVE_GD_BMP])
PHP_GD_CHECK_FORMAT([Tga], [HAVE_GD_TGA])
PHP_GD_CHECK_FORMAT([Png], [AC_DEFINE([HAVE_GD_PNG], [1])])
PHP_GD_CHECK_FORMAT([Avif], [AC_DEFINE([HAVE_GD_AVIF], [1])])
PHP_GD_CHECK_FORMAT([Webp], [AC_DEFINE([HAVE_GD_WEBP], [1])])
PHP_GD_CHECK_FORMAT([Jpeg], [AC_DEFINE([HAVE_GD_JPG], [1])])
PHP_GD_CHECK_FORMAT([Xpm], [AC_DEFINE([HAVE_GD_XPM], [1])])
PHP_GD_CHECK_FORMAT([Bmp], [AC_DEFINE([HAVE_GD_BMP], [1])])
PHP_GD_CHECK_FORMAT([Tga], [AC_DEFINE([HAVE_GD_TGA], [1])])
PHP_CHECK_LIBRARY([gd], [gdFontCacheShutdown],
[AC_DEFINE([HAVE_GD_FREETYPE], [1], [ ])],
[AC_DEFINE([HAVE_GD_FREETYPE], [1])],
[],
[$GD_SHARED_LIBADD])
PHP_CHECK_LIBRARY([gd], [gdVersionString],
[AC_DEFINE([HAVE_GD_LIBVERSION], [1], [ ])],
[AC_DEFINE([HAVE_GD_LIBVERSION], [1],
[Define to 1 if GD library has the 'gdVersionString' function.])],
[],
[$GD_SHARED_LIBADD])
PHP_CHECK_LIBRARY([gd], [gdImageGetInterpolationMethod],
[AC_DEFINE([HAVE_GD_GET_INTERPOLATION], [1], [ ])],
[AC_DEFINE([HAVE_GD_GET_INTERPOLATION], [1],
[Define to 1 if GD library has the 'gdImageGetInterpolationMethod'
function.])],
Comment on lines +213 to +215
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. gdImageGetInterpolationMethod() is available as of libgd 2.1.1; do we still support such old versions?

However, not really related to this PR; just mentioning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be merged as is however centos 8 libgd version is 2.2.5. can be addressed in another PR eventually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all in favor of bumping the libgd minimum version however issue is that bundled libgd is of version ~2.0.35. Probably adjusted already to a partially newer version. But it doesn't have the gdImageGetInterpolationMethod as an exported function yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundled libgd is of version ~2.0.35

Yeah, that is bad. There is special support for this, so it claims to be 2.1.0 compatible, but that is also wrong. In fact it is closer to 2.2 or likely even 2.3, although it is certainly not fully compatible with any system libgd. Long time ago I suggested to update the bundled GD version numbers/string, but that was rejected because the goal was to drop bundled GD – but that still didn't happen.

Anyway, we can resolve this in another PR, and just ignore this for this PR.

[],
[$GD_SHARED_LIBADD])
])
Expand Down Expand Up @@ -255,9 +270,12 @@ if test "$PHP_GD" != "no"; then
dnl These are always available with bundled library
AC_DEFINE([HAVE_GD_BUNDLED], [1],
[Define to 1 if gd extension uses GD library bundled in PHP.])
AC_DEFINE(HAVE_GD_PNG, 1, [ ])
AC_DEFINE(HAVE_GD_BMP, 1, [ ])
AC_DEFINE(HAVE_GD_TGA, 1, [ ])
AC_DEFINE([HAVE_GD_PNG], [1],
[Define to 1 if gd extension has PNG support.])
AC_DEFINE([HAVE_GD_BMP], [1],
[Define to 1 if gd extension has BMP support.])
AC_DEFINE([HAVE_GD_TGA], [1],
[Define to 1 if gd extension has TGA support.])

dnl Various checks for GD features
PHP_SETUP_ZLIB([GD_SHARED_LIBADD])
Expand Down
24 changes: 12 additions & 12 deletions ext/gd/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ if (PHP_GD != "no") {
if ((CHECK_LIB("libwebp_a.lib", "gd", PHP_GD) || CHECK_LIB("libwebp.lib", "gd", PHP_GD)) &&
CHECK_HEADER_ADD_INCLUDE("decode.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\webp") &&
CHECK_HEADER_ADD_INCLUDE("encode.h", "CFLAGS_GD", PHP_GD + ";" + PHP_PHP_BUILD + "\\include\\webp")) {
AC_DEFINE("HAVE_LIBWEBP", 1, "WebP support");
AC_DEFINE("HAVE_GD_WEBP", 1, "WebP support");
AC_DEFINE("HAVE_LIBWEBP", 1, "Define to 1 if you have the libwebp library.");
AC_DEFINE("HAVE_GD_WEBP", 1, "Define to 1 if gd extension has WebP support.");
} else {
WARNING("libwebp not enabled; libraries and headers not found");
}
Expand Down Expand Up @@ -56,16 +56,16 @@ if (PHP_GD != "no") {
gd_filter.c gd_pixelate.c gd_rotate.c gd_color_match.c gd_webp.c gd_avif.c \
gd_crop.c gd_interpolation.c gd_matrix.c gd_bmp.c gd_tga.c", "gd");
AC_DEFINE('HAVE_GD_BUNDLED', 1, "Define to 1 if gd extension uses GD library bundled in PHP.");
AC_DEFINE('HAVE_GD_PNG', 1, "PNG support");
AC_DEFINE('HAVE_GD_BMP', 1, "BMP support");
AC_DEFINE('HAVE_GD_TGA', 1, "TGA support");
AC_DEFINE('HAVE_LIBPNG', 1, "PNG support");
AC_DEFINE('HAVE_LIBJPEG', 1, "JPEG support");
AC_DEFINE('HAVE_GD_JPG', 1, "JPEG support");
AC_DEFINE('HAVE_XPM', 1, "XPM support");
AC_DEFINE('HAVE_GD_XPM', 1, "XPM support");
AC_DEFINE('HAVE_LIBFREETYPE', 1, "Freetype support");
AC_DEFINE('HAVE_GD_FREETYPE', 1, "Freetype support");
AC_DEFINE('HAVE_GD_PNG', 1, "Define to 1 if gd extension has PNG support.");
AC_DEFINE('HAVE_GD_BMP', 1, "Define to 1 if gd extension has BMP support.");
AC_DEFINE('HAVE_GD_TGA', 1, "Define to 1 if gd extension has TGA support.");
AC_DEFINE('HAVE_LIBPNG', 1, "Define to 1 if you have the libpng library.");
AC_DEFINE('HAVE_LIBJPEG', 1, "Define to 1 if you have the libjpeg library.");
AC_DEFINE('HAVE_GD_JPG', 1, "Define to 1 if gd extension has JPEG support.");
AC_DEFINE('HAVE_XPM', 1, "Define to 1 if you have the xpm library.");
AC_DEFINE('HAVE_GD_XPM', 1, "Define to 1 if gd extension has XPM support.");
AC_DEFINE('HAVE_LIBFREETYPE', 1, "Define to 1 if you have the FreeType library.");
AC_DEFINE('HAVE_GD_FREETYPE', 1, "Define to 1 if gd extension has FreeType support.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought that the bundled libgd also has JIT-mapped Japanese font support on Windows, but apparently not. For better compatibility with system libgd, we may consider to add that; on the other hand, this is a feature which always looked somewhat arbitrary to me – why not have that for other character encodings, too. Or maybe better, why not leave converting to UTF-8 up to users?

Anyhow, again unrelated to the PR at hand.

ADD_FLAG("CFLAGS_GD", " \
/D PHP_GD_EXPORTS=1 \
/D HAVE_GD_GET_INTERPOLATION \
Expand Down