summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/gd/gd.c34
-rw-r--r--ext/gd/gd.stub.php4
-rw-r--r--ext/gd/gd_arginfo.h6
3 files changed, 25 insertions, 19 deletions
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 8dfb201402..59efe998a9 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -1820,7 +1820,6 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
char *file = NULL;
zend_long quality = 0, type = 0;
gdImagePtr im;
- char *fn = NULL;
FILE *fp;
size_t file_len = 0;
int argc = ZEND_NUM_ARGS();
@@ -1828,28 +1827,35 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
/* The quality parameter for gd2 stands for chunk size */
- if (zend_parse_parameters(argc, "O|pll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
- RETURN_THROWS();
+ switch (image_type) {
+ case PHP_GDIMG_TYPE_GD:
+ if (zend_parse_parameters(argc, "O|p!", &imgind, gd_image_ce, &file, &file_len) == FAILURE) {
+ RETURN_THROWS();
+ }
+ break;
+ case PHP_GDIMG_TYPE_GD2:
+ if (zend_parse_parameters(argc, "O|p!ll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) {
+ RETURN_THROWS();
+ }
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE()
}
im = php_gd_libgdimageptr_from_zval_p(imgind);
- if (argc > 1) {
- fn = file;
- if (argc >= 3) {
- q = quality;
- if (argc == 4) {
- t = type;
- }
+ if (argc >= 3) {
+ q = quality;
+ if (argc == 4) {
+ t = type;
}
}
- if (argc >= 2 && file_len) {
- PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
+ if (file_len) {
+ PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename");
- fp = VCWD_FOPEN(fn, "wb");
+ fp = VCWD_FOPEN(file, "wb");
if (!fp) {
- php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", fn);
+ php_error_docref(NULL, E_WARNING, "Unable to open \"%s\" for writing", file);
RETURN_FALSE;
}
diff --git a/ext/gd/gd.stub.php b/ext/gd/gd.stub.php
index c108246620..e22337592c 100644
--- a/ext/gd/gd.stub.php
+++ b/ext/gd/gd.stub.php
@@ -125,9 +125,9 @@ 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 {}
-function imagegd(GdImage $image, string $file = UNKNOWN): bool {}
+function imagegd(GdImage $image, ?string $file = null): bool {}
-function imagegd2(GdImage $image, string $file = UNKNOWN, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
+function imagegd2(GdImage $image, ?string $file = null, int $chunk_size = UNKNOWN, int $mode = UNKNOWN): bool {}
#ifdef HAVE_GD_BMP
/** @param resource|string|null $file */
diff --git a/ext/gd/gd_arginfo.h b/ext/gd/gd_arginfo.h
index de974fc7d7..5a3f12f519 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: e5688b77ea52f6df10e3335594d9fc1956c10c34 */
+ * Stub hash: 884e30d9f263c5873d15cec9c2d2f1fef5b75fe6 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_gd_info, 0, 0, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@@ -238,12 +238,12 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd, 0, 1, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
- ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd2, 0, 1, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, image, GdImage, 0)
- ZEND_ARG_TYPE_INFO(0, file, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO(0, chunk_size, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
ZEND_END_ARG_INFO()