From a39dca1c77aebafdf231ef78f2c5908b3404c001 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 5 Jun 2024 23:47:25 +0100 Subject: [PATCH 1/2] ext/gd: imageclone support. --- ext/gd/config.m4 | 1 + ext/gd/gd.c | 23 +++++++++++++++++++++++ ext/gd/gd.stub.php | 4 ++++ ext/gd/gd_arginfo.h | 14 +++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index 5c1c7a867c2f8..d94a046c65190 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -198,6 +198,7 @@ AC_DEFUN([PHP_GD_CHECK_VERSION],[ 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 ]) + PHP_CHECK_LIBRARY(gd, gdImageClone, [AC_DEFINE(HAVE_GD_IMAGECLONE, 1, [ ])], [], [ $GD_SHARED_LIBADD ]) ]) dnl diff --git a/ext/gd/gd.c b/ext/gd/gd.c index ea7aa92fe0a99..1cd8b65fdd1c1 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -4169,3 +4169,26 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, } /* }}} */ + +#if defined(HAVE_GD_IMAGECLONE) +PHP_FUNCTION(imageclone) +{ + zval *IM; + gdImagePtr im; + gdImagePtr new; + + ZEND_PARSE_PARAMETERS_START(1, 1) + Z_PARAM_OBJECT_OF_CLASS(IM, gd_image_ce) + ZEND_PARSE_PARAMETERS_END(); + + im = php_gd_libgdimageptr_from_zval_p(IM); + /* TODO adding the implementation in the bundled part ? */ + new = gdImageClone(im); + + if (!new) { + RETURN_FALSE; + } + + php_gd_assign_libgdimageptr_as_extgdimage(return_value, new); +} +#endif diff --git a/ext/gd/gd.stub.php b/ext/gd/gd.stub.php index 347e43e728b87..33759d46103d4 100644 --- a/ext/gd/gd.stub.php +++ b/ext/gd/gd.stub.php @@ -794,3 +794,7 @@ function imagesetinterpolation(GdImage $image, int $method = IMG_BILINEAR_FIXED) * @refcount 1 */ function imageresolution(GdImage $image, ?int $resolution_x = null, ?int $resolution_y = null): array|bool {} + +#ifdef HAVE_GD_IMAGECLONE +function imageclone(GdImage $image): GdImage|false {} +#endif diff --git a/ext/gd/gd_arginfo.h b/ext/gd/gd_arginfo.h index f68b34d5e101b..6e3ea607133e5 100644 --- a/ext/gd/gd_arginfo.h +++ b/ext/gd/gd_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 0f8a22bff1d123313f37da400500e573baace837 */ + * Stub hash: 078828abb16cc2a3cc5113bb232e54fc315177d4 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -575,6 +575,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageresolution, 0, 1, MAY_BE_AR ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, resolution_y, IS_LONG, 1, "null") ZEND_END_ARG_INFO() +#if defined(HAVE_GD_IMAGECLONE) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imageclone, 0, 1, GdImage, MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, image, GdImage, 0) +ZEND_END_ARG_INFO() +#endif + ZEND_FUNCTION(gd_info); ZEND_FUNCTION(imageloadfont); ZEND_FUNCTION(imagesetstyle); @@ -713,6 +719,9 @@ ZEND_FUNCTION(imageaffinematrixconcat); ZEND_FUNCTION(imagegetinterpolation); ZEND_FUNCTION(imagesetinterpolation); ZEND_FUNCTION(imageresolution); +#if defined(HAVE_GD_IMAGECLONE) +ZEND_FUNCTION(imageclone); +#endif static const zend_function_entry ext_functions[] = { ZEND_FE(gd_info, arginfo_gd_info) @@ -859,6 +868,9 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(imagegetinterpolation, arginfo_imagegetinterpolation) ZEND_FE(imagesetinterpolation, arginfo_imagesetinterpolation) ZEND_FE(imageresolution, arginfo_imageresolution) +#if defined(HAVE_GD_IMAGECLONE) + ZEND_FE(imageclone, arginfo_imageclone) +#endif ZEND_FE_END }; From 46e200ae0da14ae2828db5a2f1dd17ef847c33c8 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 6 Jun 2024 12:53:21 +0100 Subject: [PATCH 2/2] add test --- ext/gd/tests/imageclone.phpt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ext/gd/tests/imageclone.phpt diff --git a/ext/gd/tests/imageclone.phpt b/ext/gd/tests/imageclone.phpt new file mode 100644 index 0000000000000..28e3affb74681 --- /dev/null +++ b/ext/gd/tests/imageclone.phpt @@ -0,0 +1,35 @@ +--TEST-- +imageclone() +--EXTENSIONS-- +gd +--SKIPIF-- + +--EXPECT-- +bool(false) +bool(true) +bool(true) +bool(true)