Skip to content

Cater to optional support of GD/GD2 image formats #15006

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions Zend/Optimizer/zend_func_infos.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ static const func_info_t func_infos[] = {
F1("imagecreatefromxpm", MAY_BE_OBJECT|MAY_BE_FALSE),
#endif
F1("imagecreatefromwbmp", MAY_BE_OBJECT|MAY_BE_FALSE),
#if defined(HAVE_GD_GD)
F1("imagecreatefromgd", MAY_BE_OBJECT|MAY_BE_FALSE),
#endif
#if defined(HAVE_GD_GD)
F1("imagecreatefromgd2", MAY_BE_OBJECT|MAY_BE_FALSE),
#endif
#if defined(HAVE_GD_GD)
F1("imagecreatefromgd2part", MAY_BE_OBJECT|MAY_BE_FALSE),
#endif
#if defined(HAVE_GD_BMP)
F1("imagecreatefrombmp", MAY_BE_OBJECT|MAY_BE_FALSE),
#endif
Expand Down
2 changes: 2 additions & 0 deletions ext/gd/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ AC_DEFUN([PHP_GD_CHECK_VERSION],[
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([Gd], [HAVE_GD_GD])
PHP_CHECK_LIBRARY(gd, gdFontCacheShutdown, [AC_DEFINE(HAVE_GD_FREETYPE, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
PHP_CHECK_LIBRARY(gd, gdVersionString, [AC_DEFINE(HAVE_GD_LIBVERSION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
PHP_CHECK_LIBRARY(gd, gdImageGetInterpolationMethod, [AC_DEFINE(HAVE_GD_GET_INTERPOLATION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
Expand Down Expand Up @@ -215,6 +216,7 @@ dnl These are always available with bundled library
AC_DEFINE(HAVE_GD_PNG, 1, [ ])
AC_DEFINE(HAVE_GD_BMP, 1, [ ])
AC_DEFINE(HAVE_GD_TGA, 1, [ ])
AC_DEFINE(HAVE_GD_GD, 1, [ ])

dnl Various checks for GD features
PHP_SETUP_ZLIB([GD_SHARED_LIBADD])
Expand Down
1 change: 1 addition & 0 deletions ext/gd/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ if (PHP_GD != "no") {
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_GD_GD', 1, "GD/GD2 format support");
AC_DEFINE('HAVE_LIBFREETYPE', 1, "Freetype support");
AC_DEFINE('HAVE_GD_FREETYPE', 1, "Freetype support");
ADD_FLAG("CFLAGS_GD", " \
Expand Down
15 changes: 15 additions & 0 deletions ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ PHP_MINFO_FUNCTION(gd)
#endif
#ifdef HAVE_GD_TGA
php_info_print_table_row(2, "TGA Read Support", "enabled");
#endif
#ifdef HAVE_GD_GD
php_info_print_table_row(2, "GD/GD2 Support", "enabled");
#endif
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
Expand Down Expand Up @@ -514,6 +517,11 @@ PHP_FUNCTION(gd_info)
#else
add_assoc_bool(return_value, "TGA Read Support", 0);
#endif
#ifdef HAVE_GD_GD
add_assoc_bool(return_value, "GD/GD2 Support", 1);
#else
add_assoc_bool(return_value, "GD/GD2 Support", 0);
#endif
#ifdef USE_GD_JISX0208
add_assoc_bool(return_value, "JIS-mapped Japanese Font Support", 1);
#else
Expand Down Expand Up @@ -1346,6 +1354,9 @@ PHP_FUNCTION(imagetypes)
#ifdef HAVE_GD_AVIF
ret |= PHP_IMG_AVIF;
#endif
#ifdef HAVE_GD_GD
ret |= PHP_IMG_GD;
#endif

ZEND_PARSE_PARAMETERS_NONE();

Expand Down Expand Up @@ -1719,6 +1730,7 @@ PHP_FUNCTION(imagecreatefromwbmp)
}
/* }}} */

#ifdef HAVE_GD_GD
/* {{{ Create a new image from GD file or URL */
PHP_FUNCTION(imagecreatefromgd)
{
Expand All @@ -1739,6 +1751,7 @@ PHP_FUNCTION(imagecreatefromgd2part)
_php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2PART, "GD2", NULL, NULL);
}
/* }}} */
#endif /* HAVE_GD_GD */

#ifdef HAVE_GD_BMP
/* {{{ Create a new image from BMP file or URL */
Expand Down Expand Up @@ -2131,6 +2144,7 @@ PHP_FUNCTION(imagewbmp)
}
/* }}} */

#ifdef HAVE_GD_GD
/* {{{ Output GD image to browser or file */
PHP_FUNCTION(imagegd)
{
Expand All @@ -2144,6 +2158,7 @@ PHP_FUNCTION(imagegd2)
_php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GD2, "GD2");
}
/* }}} */
#endif /* HAVE_GD_GD */

#ifdef HAVE_GD_BMP
/* {{{ Output BMP image to browser or file */
Expand Down
9 changes: 9 additions & 0 deletions ext/gd/gd.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
* @cvalue PHP_IMG_TGA
*/
const IMG_TGA = UNKNOWN;
/**
* @var int
* @cvalue PHP_IMG_GD
*/
const IMG_GD = UNKNOWN;

/* constant for webp encoding */

Expand Down Expand Up @@ -580,6 +585,7 @@ function imagecreatefromxpm(string $filename): GdImage|false {}
/** @refcount 1 */
function imagecreatefromwbmp(string $filename): GdImage|false {}

#ifdef HAVE_GD_GD
/** @refcount 1 */
function imagecreatefromgd(string $filename): GdImage|false {}

Expand All @@ -588,6 +594,7 @@ function imagecreatefromgd2(string $filename): GdImage|false {}

/** @refcount 1 */
function imagecreatefromgd2part(string $filename, int $x, int $y, int $width, int $height): GdImage|false {}
#endif

#ifdef HAVE_GD_BMP
/** @refcount 1 */
Expand Down Expand Up @@ -626,9 +633,11 @@ function imagejpeg(GdImage $image, $file = null, int $quality = -1): bool {}
/** @param resource|string|null $file */
function imagewbmp(GdImage $image, $file = null, ?int $foreground_color = null): bool {}

#ifdef HAVE_GD_GD
function imagegd(GdImage $image, ?string $file = null): bool {}

function imagegd2(GdImage $image, ?string $file = null, int $chunk_size = 128, int $mode = IMG_GD2_RAW): bool {}
#endif

#ifdef HAVE_GD_BMP
/** @param resource|string|null $file */
Expand Down
39 changes: 36 additions & 3 deletions ext/gd/gd_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/gd/php_gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define PHP_IMG_BMP 64
#define PHP_IMG_TGA 128
#define PHP_IMG_AVIF 256
#define PHP_IMG_GD 512

/* Section Filters Declarations */
/* IMPORTANT NOTE FOR NEW FILTER
Expand Down
Loading