From 3d78a0cdb692b8e916521f3204e97ea25be826d8 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 27 Aug 2019 00:18:20 +0100 Subject: [PATCH 01/11] Helper file for GD functions Remove test helper from root Initial progress on converting GD to use objects Removal of unnecessary tests, removal of image pointer validation Moved object defs out of magical header file Removed check on image free, fixed evaluating zval offset, fixed ce flags, tabs Switched posix test to use curl instead of gd as it is no longer a resource GdImage cannot be cloned gd image object handlers in standalone file --- ext/gd/gd.c | 750 +++++++++--------- ext/gd/gd.stub.php | 152 ++-- ext/gd/gd_arginfo.h | 125 +-- ext/gd/gd_ctx.c | 217 ----- ext/gd/gd_image_object.c | 73 ++ ext/gd/gd_image_object.h | 36 + ext/gd/php_gd.h | 1 + ext/gd/tests/bug41442.phpt | 8 +- ext/gd/tests/bug66356.phpt | 16 +- ext/gd/tests/bug70976.phpt | 3 +- ext/gd/tests/bug73968.phpt | 7 +- ext/gd/tests/bug74435.phpt | 7 +- ext/gd/tests/bug77269.phpt | 5 +- ext/gd/tests/bug77391.phpt | 7 +- ext/gd/tests/gdimage_prevent_cloning.phpt | 20 + ext/gd/tests/imageantialias_error1.phpt | 21 - ext/gd/tests/imagechar_error2.phpt | 21 - ext/gd/tests/imagecharup_error2.phpt | 21 - .../tests/imagecolorallocatealpha_error1.phpt | 19 - ext/gd/tests/imagecolordeallocate_error1.phpt | 26 - ext/gd/tests/imagecolordeallocate_error3.phpt | 13 +- ext/gd/tests/imagecolordeallocate_error4.phpt | 13 +- ext/gd/tests/imagecolorstotal_error.phpt | 39 - ext/gd/tests/imageellipse_error7.phpt | 24 - ext/gd/tests/imagefilltoborder_error6.phpt | 31 - ext/gd/tests/imagefilter_error10.phpt | 21 - ext/gd/tests/imagegammacorrect_error2.phpt | 21 - ext/gd/tests/imageinterlace_error2.phpt | 20 - ext/gd/tests/imageistruecolor_error1.phpt | 20 - ext/gd/tests/imagelayereffect_error3.phpt | 21 - .../tests/imagepalettetotruecolor_basic.phpt | 2 +- .../tests/imagepalettetotruecolor_error3.phpt | 19 - ext/gd/tests/imagerectangle_error2.phpt | 23 - ext/gd/tests/imagesetthickness_error1.phpt | 19 - ext/gd/tests/imagestring_error2.phpt | 21 - ext/gd/tests/imagestringup_error2.phpt | 21 - .../tests/imagetruecolortopalette_error1.phpt | 20 - .../posix_ttyname_error_wrongparams.phpt | 11 +- 38 files changed, 705 insertions(+), 1189 deletions(-) delete mode 100644 ext/gd/gd_ctx.c create mode 100644 ext/gd/gd_image_object.c create mode 100644 ext/gd/gd_image_object.h create mode 100644 ext/gd/tests/gdimage_prevent_cloning.phpt delete mode 100644 ext/gd/tests/imageantialias_error1.phpt delete mode 100644 ext/gd/tests/imagechar_error2.phpt delete mode 100644 ext/gd/tests/imagecharup_error2.phpt delete mode 100644 ext/gd/tests/imagecolorallocatealpha_error1.phpt delete mode 100644 ext/gd/tests/imagecolordeallocate_error1.phpt delete mode 100644 ext/gd/tests/imagecolorstotal_error.phpt delete mode 100644 ext/gd/tests/imageellipse_error7.phpt delete mode 100644 ext/gd/tests/imagefilltoborder_error6.phpt delete mode 100644 ext/gd/tests/imagefilter_error10.phpt delete mode 100644 ext/gd/tests/imagegammacorrect_error2.phpt delete mode 100644 ext/gd/tests/imageinterlace_error2.phpt delete mode 100644 ext/gd/tests/imageistruecolor_error1.phpt delete mode 100644 ext/gd/tests/imagelayereffect_error3.phpt delete mode 100644 ext/gd/tests/imagepalettetotruecolor_error3.phpt delete mode 100644 ext/gd/tests/imagerectangle_error2.phpt delete mode 100644 ext/gd/tests/imagesetthickness_error1.phpt delete mode 100644 ext/gd/tests/imagestring_error2.phpt delete mode 100644 ext/gd/tests/imagestringup_error2.phpt delete mode 100644 ext/gd/tests/imagetruecolortopalette_error1.phpt diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 4f93d62c5190d..b621bc23bd107 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -55,10 +55,11 @@ # include #endif -# include "gd_compat.h" +#include "gd_compat.h" +#include "gd_image_object.h" -static int le_gd, le_gd_font; +static int le_gd_font; #include #include @@ -85,7 +86,6 @@ static int le_gd, le_gd_font; static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int, int); #endif -#include "gd_ctx.c" #include "gd_arginfo.h" /* as it is not really public, duplicate declaration here to avoid @@ -306,14 +306,204 @@ PHP_INI_BEGIN() PHP_INI_END() /* }}} */ -/* {{{ php_free_gd_image - */ -static void php_free_gd_image(zend_resource *rsrc) + +#define CTX_PUTC(c,ctx) ctx->putC(ctx, c) + + static void _php_image_output_putc(struct gdIOCtx *ctx, int c) /* {{{ */ +{ + /* without the following downcast, the write will fail + * (i.e., will write a zero byte) for all + * big endian architectures: + */ + unsigned char ch = (unsigned char) c; + php_write(&ch, 1); +} /* }}} */ + +static int _php_image_output_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ +{ + return php_write((void *)buf, l); +} /* }}} */ + +static void _php_image_output_ctxfree(struct gdIOCtx *ctx) /* {{{ */ +{ + if(ctx) { + efree(ctx); + } +} /* }}} */ + +static void _php_image_stream_putc(struct gdIOCtx *ctx, int c) /* {{{ */ { + char ch = (char) c; + php_stream * stream = (php_stream *)ctx->data; + php_stream_write(stream, &ch, 1); +} /* }}} */ + +static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ +{ + php_stream * stream = (php_stream *)ctx->data; + return php_stream_write(stream, (void *)buf, l); +} /* }}} */ + +static void _php_image_stream_ctxfree(struct gdIOCtx *ctx) /* {{{ */ { - gdImageDestroy((gdImagePtr) rsrc->ptr); + if(ctx->data) { + ctx->data = NULL; + } + if(ctx) { + efree(ctx); + } +} /* }}} */ + +static void _php_image_stream_ctxfreeandclose(struct gdIOCtx *ctx) /* {{{ */ +{ + + if(ctx->data) { + php_stream_close((php_stream *) ctx->data); + ctx->data = NULL; + } + if(ctx) { + efree(ctx); + } +} /* }}} */ + +/* {{{ _php_image_output_ctx */ +static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) +{ + zval *imgind; + char *file = NULL; + size_t file_len = 0; + zend_long quality, basefilter; + zend_bool compressed = 1; + gdImagePtr im; + int argc = ZEND_NUM_ARGS(); + int q = -1, i; + int f = -1; + gdIOCtx *ctx = NULL; + zval *to_zval = NULL; + php_stream *stream; + int close_stream = 1; + + /* The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called + * from imagey(). + */ + switch (image_type) { + case PHP_GDIMG_TYPE_XBM: + if (zend_parse_parameters(argc, "Op!|ll", &imgind, gd_image_ce, &file, &file_len, &quality, &basefilter) == FAILURE) { + return; + } + break; + case PHP_GDIMG_TYPE_BMP: + if (zend_parse_parameters(argc, "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) { + return; + } + break; + default: + /* PHP_GDIMG_TYPE_GIF + * PHP_GDIMG_TYPE_PNG + * PHP_GDIMG_TYPE_JPG + * PHP_GDIMG_TYPE_WBM + * PHP_GDIMG_TYPE_WEBP + * */ + if (zend_parse_parameters(argc, "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &basefilter) == FAILURE) { + return; + } + } + + im = php_gd_image_ptr_from_zval_p(imgind); + + if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3) { + q = quality; /* or colorindex for foreground of BW images (defaults to black) */ + if (argc == 4) { + f = basefilter; + } + } + + if (argc > 1 && to_zval != NULL) { + if (Z_TYPE_P(to_zval) == IS_RESOURCE) { + php_stream_from_zval_no_verify(stream, to_zval); + if (stream == NULL) { + RETURN_FALSE; + } + close_stream = 0; + } else if (Z_TYPE_P(to_zval) == IS_STRING) { + if (CHECK_ZVAL_NULL_PATH(to_zval)) { + zend_type_error("Invalid 2nd parameter, filename must not contain null bytes"); + return; + } + + stream = php_stream_open_wrapper(Z_STRVAL_P(to_zval), "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); + if (stream == NULL) { + RETURN_FALSE; + } + } else { + php_error_docref(NULL, E_WARNING, "Invalid 2nd parameter, it must a filename or a stream"); + RETURN_FALSE; + } + } else if (argc > 1 && file != NULL) { + stream = php_stream_open_wrapper(file, "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); + if (stream == NULL) { + RETURN_FALSE; + } + } else { + ctx = ecalloc(1, sizeof(gdIOCtx)); + ctx->putC = _php_image_output_putc; + ctx->putBuf = _php_image_output_putbuf; + ctx->gd_free = _php_image_output_ctxfree; + } + + if (!ctx) { + ctx = ecalloc(1, sizeof(gdIOCtx)); + ctx->putC = _php_image_stream_putc; + ctx->putBuf = _php_image_stream_putbuf; + if (close_stream) { + ctx->gd_free = _php_image_stream_ctxfreeandclose; + } else { + ctx->gd_free = _php_image_stream_ctxfree; + } + ctx->data = (void *)stream; + } + + switch(image_type) { + case PHP_GDIMG_TYPE_JPG: + (*func_p)(im, ctx, q); + break; + case PHP_GDIMG_TYPE_WEBP: + if (q == -1) { + q = 80; + } + (*func_p)(im, ctx, q); + break; + case PHP_GDIMG_TYPE_PNG: + (*func_p)(im, ctx, q, f); + break; + case PHP_GDIMG_TYPE_XBM: + case PHP_GDIMG_TYPE_WBM: + if (argc < 3) { + for(i=0; i < gdImageColorsTotal(im); i++) { + if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; + } + q = i; + } + if (image_type == PHP_GDIMG_TYPE_XBM) { + (*func_p)(im, file ? file : "", q, ctx); + } else { + (*func_p)(im, q, ctx); + } + break; + case PHP_GDIMG_TYPE_BMP: + (*func_p)(im, ctx, (int) compressed); + break; + default: + (*func_p)(im, ctx); + break; + } + + ctx->gd_free(ctx); + + RETURN_TRUE; } /* }}} */ + /* {{{ php_free_gd_font */ static void php_free_gd_font(zend_resource *rsrc) @@ -351,12 +541,18 @@ void php_gd_error_method(int type, const char *format, va_list args) } /* }}} */ +static zend_object_handlers gd_ext_image_object_handlers; + +static const zend_function_entry gd_image_methods[] = { + PHP_FE_END +}; + /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(gd) { - le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number); le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number); + php_gd_object_minit_helper(); #if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED) gdFontCacheMutexSetup(); @@ -665,13 +861,6 @@ PHP_FUNCTION(gd_info) } /* }}} */ -/* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */ -PHP_GD_API int phpi_get_le_gd(void) -{ - return le_gd; -} -/* }}} */ - #define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24)) /* {{{ proto int imageloadfont(string filename) @@ -788,13 +977,11 @@ PHP_FUNCTION(imagesetstyle) int index = 0; uint32_t num_styles; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra", &IM, &styles) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &styles) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles)); if (num_styles == 0) { @@ -844,7 +1031,7 @@ PHP_FUNCTION(imagecreatetruecolor) RETURN_FALSE; } - RETURN_RES(zend_register_resource(im, le_gd)); + php_gd_image_object_from_gd_ptr(return_value, im); } /* }}} */ @@ -855,13 +1042,11 @@ PHP_FUNCTION(imageistruecolor) zval *IM; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &IM) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &IM, gd_image_ce) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); RETURN_BOOL(im->trueColor); } @@ -876,13 +1061,11 @@ PHP_FUNCTION(imagetruecolortopalette) zend_long ncolors; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rbl", &IM, &dither, &ncolors) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Obl", &IM, gd_image_ce, &dither, &ncolors) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (ncolors <= 0 || ZEND_LONG_INT_OVFL(ncolors)) { zend_value_error("Number of colors has to be greater than zero and no more than %d", INT_MAX); @@ -905,13 +1088,11 @@ PHP_FUNCTION(imagepalettetotruecolor) zval *IM; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &IM) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &IM, gd_image_ce) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (gdImagePaletteToTrueColor(im) == 0) { RETURN_FALSE; @@ -929,16 +1110,12 @@ PHP_FUNCTION(imagecolormatch) gdImagePtr im1, im2; int result; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &IM1, &IM2) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &IM1, gd_image_ce, &IM2, gd_image_ce) == FAILURE) { return; } - if ((im1 = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM1), "Image", le_gd)) == NULL) { - return; - } - if ((im2 = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM2), "Image", le_gd)) == NULL) { - return; - } + im1 = php_gd_image_ptr_from_zval_p(IM1); + im2 = php_gd_image_ptr_from_zval_p(IM2); result = gdImageColorMatch(im1, im2); switch (result) { @@ -972,13 +1149,11 @@ PHP_FUNCTION(imagesetthickness) zend_long thick; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &IM, &thick) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &IM, gd_image_ce, &thick) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageSetThickness(im, thick); @@ -994,13 +1169,11 @@ PHP_FUNCTION(imagefilledellipse) zend_long cx, cy, w, h, color; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllll", &IM, gd_image_ce, &cx, &cy, &w, &h, &color) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageFilledEllipse(im, cx, cy, w, h, color); @@ -1017,13 +1190,11 @@ PHP_FUNCTION(imagefilledarc) gdImagePtr im; int e, st; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollllllll", &IM, gd_image_ce, &cx, &cy, &w, &h, &ST, &E, &col, &style) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); e = E; if (e < 0) { @@ -1049,13 +1220,11 @@ PHP_FUNCTION(imagealphablending) zend_bool blend; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &IM, &blend) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &IM, gd_image_ce, &blend) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageAlphaBlending(im, blend); @@ -1071,13 +1240,11 @@ PHP_FUNCTION(imagesavealpha) zend_bool save; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &IM, &save) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &IM, gd_image_ce, &save) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageSaveAlpha(im, save); @@ -1093,13 +1260,11 @@ PHP_FUNCTION(imagelayereffect) zend_long effect; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &IM, &effect) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &IM, gd_image_ce, &effect) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageAlphaBlending(im, effect); @@ -1122,13 +1287,11 @@ PHP_FUNCTION(imagecolorallocatealpha) gdImagePtr im; int ct = (-1); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll", &IM, gd_image_ce, &red, &green, &blue, &alpha) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1151,13 +1314,11 @@ PHP_FUNCTION(imagecolorresolvealpha) zend_long red, green, blue, alpha; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll", &IM, gd_image_ce, &red, &green, &blue, &alpha) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1176,13 +1337,11 @@ PHP_FUNCTION(imagecolorclosestalpha) zend_long red, green, blue, alpha; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll", &IM, gd_image_ce, &red, &green, &blue, &alpha) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1201,13 +1360,11 @@ PHP_FUNCTION(imagecolorexactalpha) zend_long red, green, blue, alpha; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll", &IM, &red, &green, &blue, &alpha) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll", &IM, gd_image_ce, &red, &green, &blue, &alpha) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1227,17 +1384,12 @@ PHP_FUNCTION(imagecopyresampled) gdImagePtr im_dst, im_src; int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OOllllllll", &DIM, gd_image_ce, &SIM, gd_image_ce, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { return; } - if ((im_dst = (gdImagePtr)zend_fetch_resource(Z_RES_P(DIM), "Image", le_gd)) == NULL) { - return; - } - - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_src = php_gd_image_ptr_from_zval_p(SIM); + im_dst = php_gd_image_ptr_from_zval_p(DIM); srcX = SX; srcY = SY; @@ -1319,9 +1471,9 @@ PHP_FUNCTION(imagegrabwindow) if (!im) { RETURN_FALSE; - } else { - RETURN_RES(zend_register_resource(im, le_gd)); } + + RETURN_OBJ(gd_ext_image_object_init(return_value, im)); } /* }}} */ @@ -1376,9 +1528,9 @@ PHP_FUNCTION(imagegrabscreen) if (!im) { RETURN_FALSE; - } else { - RETURN_RES(zend_register_resource(im, le_gd)); } + + php_gd_image_object_from_gd_ptr(return_value, im); } /* }}} */ #endif /* PHP_WIN32 */ @@ -1393,21 +1545,18 @@ PHP_FUNCTION(imagerotate) zend_long color; zend_long ignoretransparent = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rdl|l", &SIM, °rees, &color, &ignoretransparent) == FAILURE) { - return; - } - - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Odl|l", &SIM, gd_image_ce, °rees, &color, &ignoretransparent) == FAILURE) { return; } + im_src = php_gd_image_ptr_from_zval_p(SIM); im_dst = gdImageRotateInterpolated(im_src, (const float)degrees, color); - if (im_dst != NULL) { - RETURN_RES(zend_register_resource(im_dst, le_gd)); - } else { + if (im_dst == NULL) { RETURN_FALSE; } + + php_gd_image_object_from_gd_ptr(return_value, im_dst); } /* }}} */ @@ -1418,17 +1567,12 @@ PHP_FUNCTION(imagesettile) zval *IM, *TILE; gdImagePtr im, tile; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &IM, &TILE) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &IM, gd_image_ce, &TILE, gd_image_ce) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } - - if ((tile = (gdImagePtr)zend_fetch_resource(Z_RES_P(TILE), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); + tile = php_gd_image_ptr_from_zval_p(TILE); gdImageSetTile(im, tile); @@ -1443,17 +1587,12 @@ PHP_FUNCTION(imagesetbrush) zval *IM, *TILE; gdImagePtr im, tile; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &IM, &TILE) == FAILURE) { - return; - } - - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &IM, gd_image_ce, &TILE, gd_image_ce) == FAILURE) { return; } - if ((tile = (gdImagePtr)zend_fetch_resource(Z_RES_P(TILE), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); + tile = php_gd_image_ptr_from_zval_p(TILE); gdImageSetBrush(im, tile); @@ -1488,7 +1627,7 @@ PHP_FUNCTION(imagecreate) RETURN_FALSE; } - RETURN_RES(zend_register_resource(im, le_gd)); + php_gd_image_object_from_gd_ptr(return_value, im); } /* }}} */ @@ -1688,7 +1827,7 @@ PHP_FUNCTION(imagecreatefromstring) RETURN_FALSE; } - RETURN_RES(zend_register_resource(im, le_gd)); + php_gd_image_object_from_gd_ptr(return_value, im); } /* }}} */ @@ -1805,8 +1944,8 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, /* register_im: */ if (im) { - RETVAL_RES(zend_register_resource(im, le_gd)); php_stream_close(stream); + php_gd_image_object_from_gd_ptr(return_value, im); return; } @@ -1942,13 +2081,11 @@ 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, "r|pll", &imgind, &file, &file_len, &quality, &type) == FAILURE) { + if (zend_parse_parameters(argc, "O|pll", &imgind, gd_image_ce, &file, &file_len, &quality, &type) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(imgind), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(imgind); if (argc > 1) { fn = file; @@ -2125,22 +2262,16 @@ PHP_FUNCTION(imagebmp) #endif /* {{{ proto bool imagedestroy(resource im) - Destroy an image */ + Destroy an image - No effect as of PHP 8.0 */ PHP_FUNCTION(imagedestroy) { + /* This function used to free the resource, as resources are no longer used, it does nothing */ zval *IM; - gdImagePtr im; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &IM) == FAILURE) { - return; - } - - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &IM, gd_image_ce) == FAILURE) { return; } - zend_list_close(Z_RES_P(IM)); - RETURN_TRUE; } /* }}} */ @@ -2154,13 +2285,11 @@ PHP_FUNCTION(imagecolorallocate) gdImagePtr im; int ct = (-1); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll", &IM, &red, &green, &blue) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olll", &IM, gd_image_ce, &red, &green, &blue) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2181,17 +2310,12 @@ PHP_FUNCTION(imagepalettecopy) zval *dstim, *srcim; gdImagePtr dst, src; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rr", &dstim, &srcim) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OO", &dstim, gd_image_ce, &srcim, gd_image_ce) == FAILURE) { return; } - if ((dst = (gdImagePtr)zend_fetch_resource(Z_RES_P(dstim), "Image", le_gd)) == NULL) { - return; - } - - if ((src = (gdImagePtr)zend_fetch_resource(Z_RES_P(srcim), "Image", le_gd)) == NULL) { - return; - } + src = php_gd_image_ptr_from_zval_p(srcim); + dst = php_gd_image_ptr_from_zval_p(dstim); gdImagePaletteCopy(dst, src); } @@ -2206,14 +2330,12 @@ PHP_FUNCTION(imagecolorat) gdImagePtr im; ZEND_PARSE_PARAMETERS_START(3, 3) - Z_PARAM_RESOURCE(IM) + Z_PARAM_OBJECT_OF_CLASS(IM, gd_image_ce) Z_PARAM_LONG(x) Z_PARAM_LONG(y) ZEND_PARSE_PARAMETERS_END(); - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (gdImageTrueColor(im)) { if (im->tpixels && gdImageBoundsSafe(im, x, y)) { @@ -2241,13 +2363,11 @@ PHP_FUNCTION(imagecolorclosest) zend_long red, green, blue; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll", &IM, &red, &green, &blue) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olll", &IM, gd_image_ce, &red, &green, &blue) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2265,13 +2385,11 @@ PHP_FUNCTION(imagecolorclosesthwb) zend_long red, green, blue; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll", &IM, &red, &green, &blue) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olll", &IM, gd_image_ce, &red, &green, &blue) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2290,13 +2408,11 @@ PHP_FUNCTION(imagecolordeallocate) int col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &IM, &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &IM, gd_image_ce, &index) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); /* We can return right away for a truecolor image as deallocating colours is meaningless here */ if (gdImageTrueColor(im)) { @@ -2309,8 +2425,8 @@ PHP_FUNCTION(imagecolordeallocate) gdImageColorDeallocate(im, col); RETURN_TRUE; } else { - php_error_docref(NULL, E_WARNING, "Color index %d out of range", col); - RETURN_FALSE; + zend_value_error("Color index %d out of range", col); + return; } } /* }}} */ @@ -2323,13 +2439,11 @@ PHP_FUNCTION(imagecolorresolve) zend_long red, green, blue; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll", &IM, &red, &green, &blue) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olll", &IM, gd_image_ce, &red, &green, &blue) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2347,13 +2461,11 @@ PHP_FUNCTION(imagecolorexact) zend_long red, green, blue; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll", &IM, &red, &green, &blue) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olll", &IM, gd_image_ce, &red, &green, &blue) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2372,13 +2484,11 @@ PHP_FUNCTION(imagecolorset) int col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll|l", &IM, &color, &red, &green, &blue, &alpha) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll|l", &IM, gd_image_ce, &color, &red, &green, &blue, &alpha) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2407,13 +2517,11 @@ PHP_FUNCTION(imagecolorsforindex) int col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &IM, &index) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &IM, gd_image_ce, &index) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); col = index; @@ -2440,7 +2548,7 @@ PHP_FUNCTION(imagegammacorrect) int i; double input, output, gamma; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rdd", &IM, &input, &output) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Odd", &IM, gd_image_ce, &input, &output) == FAILURE) { return; } @@ -2451,9 +2559,7 @@ PHP_FUNCTION(imagegammacorrect) gamma = input / output; - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (gdImageTrueColor(im)) { int x, y, c; @@ -2493,15 +2599,13 @@ PHP_FUNCTION(imagesetpixel) gdImagePtr im; ZEND_PARSE_PARAMETERS_START(4, 4) - Z_PARAM_RESOURCE(IM) + Z_PARAM_OBJECT_OF_CLASS(IM, gd_image_ce) Z_PARAM_LONG(x) Z_PARAM_LONG(y) Z_PARAM_LONG(col) ZEND_PARSE_PARAMETERS_END(); - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageSetPixel(im, x, y, col); RETURN_TRUE; @@ -2516,13 +2620,11 @@ PHP_FUNCTION(imageline) zend_long x1, y1, x2, y2, col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllll", &IM, gd_image_ce, &x1, &y1, &x2, &y2, &col) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (im->AA) { gdImageSetAntiAliased(im, col); @@ -2541,13 +2643,11 @@ PHP_FUNCTION(imagedashedline) zend_long x1, y1, x2, y2, col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllll", &IM, gd_image_ce, &x1, &y1, &x2, &y2, &col) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageDashedLine(im, x1, y1, x2, y2, col); RETURN_TRUE; @@ -2562,13 +2662,11 @@ PHP_FUNCTION(imagerectangle) zend_long x1, y1, x2, y2, col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllll", &IM, gd_image_ce, &x1, &y1, &x2, &y2, &col) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageRectangle(im, x1, y1, x2, y2, col); RETURN_TRUE; @@ -2583,13 +2681,11 @@ PHP_FUNCTION(imagefilledrectangle) zend_long x1, y1, x2, y2, col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllll", &IM, &x1, &y1, &x2, &y2, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllll", &IM, gd_image_ce, &x1, &y1, &x2, &y2, &col) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageFilledRectangle(im, x1, y1, x2, y2, col); RETURN_TRUE; } @@ -2604,13 +2700,11 @@ PHP_FUNCTION(imagearc) gdImagePtr im; int e, st; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllllll", &IM, &cx, &cy, &w, &h, &ST, &E, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllllll", &IM, gd_image_ce, &cx, &cy, &w, &h, &ST, &E, &col) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); e = E; if (e < 0) { @@ -2635,13 +2729,11 @@ PHP_FUNCTION(imageellipse) zend_long cx, cy, w, h, color; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllll", &IM, &cx, &cy, &w, &h, &color) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllll", &IM, gd_image_ce, &cx, &cy, &w, &h, &color) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageEllipse(im, cx, cy, w, h, color); RETURN_TRUE; @@ -2656,13 +2748,11 @@ PHP_FUNCTION(imagefilltoborder) zend_long x, y, border, col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll", &IM, &x, &y, &border, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll", &IM, gd_image_ce, &x, &y, &border, &col) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageFillToBorder(im, x, y, border, col); RETURN_TRUE; @@ -2677,13 +2767,11 @@ PHP_FUNCTION(imagefill) zend_long x, y, col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll", &IM, &x, &y, &col) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olll", &IM, gd_image_ce, &x, &y, &col) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); gdImageFill(im, x, y, col); RETURN_TRUE; @@ -2697,13 +2785,11 @@ PHP_FUNCTION(imagecolorstotal) zval *IM; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &IM) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &IM, gd_image_ce) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); RETURN_LONG(gdImageColorsTotal(im)); } @@ -2718,13 +2804,11 @@ PHP_FUNCTION(imagecolortransparent) gdImagePtr im; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc, "r|l", &IM, &COL) == FAILURE) { + if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &COL) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (argc > 1) { gdImageColorTransparent(im, COL); @@ -2743,13 +2827,11 @@ PHP_FUNCTION(imageinterlace) zend_long INT = 0; gdImagePtr im; - if (zend_parse_parameters(argc, "r|l", &IM, &INT) == FAILURE) { + if (zend_parse_parameters(argc, "O|l", &IM, gd_image_ce, &INT) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (argc > 1) { gdImageInterlace(im, INT); @@ -2773,13 +2855,11 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) gdPointPtr points; int npoints, col, nelem, i; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rall", &IM, &POINTS, &NPOINTS, &COL) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oall", &IM, gd_image_ce, &POINTS, &NPOINTS, &COL) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); npoints = NPOINTS; col = COL; @@ -2974,13 +3054,11 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode) unsigned char *str = NULL; gdFontPtr font; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlllsl", &IM, &SIZE, &X, &Y, &C, &C_len, &COL) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olllsl", &IM, gd_image_ce, &SIZE, &X, &Y, &C, &C_len, &COL) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); col = COL; @@ -3067,17 +3145,12 @@ PHP_FUNCTION(imagecopy) gdImagePtr im_dst, im_src; int srcH, srcW, srcY, srcX, dstY, dstX; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OOllllll", &DIM, gd_image_ce, &SIM, gd_image_ce, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) { return; } - if ((im_dst = (gdImagePtr)zend_fetch_resource(Z_RES_P(DIM), "Image", le_gd)) == NULL) { - return; - } - - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_dst = php_gd_image_ptr_from_zval_p(DIM); + im_src = php_gd_image_ptr_from_zval_p(SIM); srcX = SX; srcY = SY; @@ -3100,17 +3173,12 @@ PHP_FUNCTION(imagecopymerge) gdImagePtr im_dst, im_src; int srcH, srcW, srcY, srcX, dstY, dstX, pct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OOlllllll", &DIM, gd_image_ce, &SIM, gd_image_ce, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { return; } - if ((im_dst = (gdImagePtr)zend_fetch_resource(Z_RES_P(DIM), "Image", le_gd)) == NULL) { - return; - } - - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_src = php_gd_image_ptr_from_zval_p(SIM); + im_dst = php_gd_image_ptr_from_zval_p(DIM); srcX = SX; srcY = SY; @@ -3134,18 +3202,13 @@ PHP_FUNCTION(imagecopymergegray) gdImagePtr im_dst, im_src; int srcH, srcW, srcY, srcX, dstY, dstX, pct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrlllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { - return; - } - - if ((im_dst = (gdImagePtr)zend_fetch_resource(Z_RES_P(DIM), "Image", le_gd)) == NULL) { - return; - } - - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OOlllllll", &DIM, gd_image_ce, &SIM, gd_image_ce, &DX, &DY, &SX, &SY, &SW, &SH, &PCT) == FAILURE) { return; } + im_src = php_gd_image_ptr_from_zval_p(SIM); + im_dst = php_gd_image_ptr_from_zval_p(DIM); + srcX = SX; srcY = SY; srcH = SH; @@ -3168,18 +3231,13 @@ PHP_FUNCTION(imagecopyresized) gdImagePtr im_dst, im_src; int srcH, srcW, dstH, dstW, srcY, srcX, dstY, dstX; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rrllllllll", &DIM, &SIM, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { - return; - } - - if ((im_dst = (gdImagePtr)zend_fetch_resource(Z_RES_P(DIM), "Image", le_gd)) == NULL) { - return; - } - - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OOllllllll", &DIM, gd_image_ce, &SIM, gd_image_ce, &DX, &DY, &SX, &SY, &DW, &DH, &SW, &SH) == FAILURE) { return; } + im_src = php_gd_image_ptr_from_zval_p(SIM); + im_dst = php_gd_image_ptr_from_zval_p(DIM); + srcX = SX; srcY = SY; srcH = SH; @@ -3190,7 +3248,7 @@ PHP_FUNCTION(imagecopyresized) dstW = DW; if (dstW <= 0 || dstH <= 0 || srcW <= 0 || srcH <= 0) { - php_error_docref(NULL, E_WARNING, "Invalid image dimensions"); + zend_value_error("Invalid image dimensions"); RETURN_FALSE; } @@ -3206,13 +3264,11 @@ PHP_FUNCTION(imagesx) zval *IM; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &IM) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &IM, gd_image_ce) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); RETURN_LONG(gdImageSX(im)); } @@ -3225,13 +3281,11 @@ PHP_FUNCTION(imagesy) zval *IM; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &IM) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &IM, gd_image_ce) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); RETURN_LONG(gdImageSY(im)); } @@ -3245,13 +3299,11 @@ PHP_FUNCTION(imagesetclip) gdImagePtr im; zend_long x1, y1, x2, y2; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll", &im_zval, &x1, &y1, &x2, &y2) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll", &im_zval, gd_image_ce, &x1, &y1, &x2, &y2) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(im_zval), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(im_zval); gdImageSetClip(im, x1, y1, x2, y2); RETURN_TRUE; @@ -3266,13 +3318,11 @@ PHP_FUNCTION(imagegetclip) gdImagePtr im; int x1, y1, x2, y2; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &im_zval) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &im_zval, gd_image_ce) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(im_zval), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(im_zval); gdImageGetClip(im, &x1, &y1, &x2, &y2); @@ -3344,12 +3394,10 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int } else { if (argc < 8 || argc > ((extended) ? 9 : 8)) { ZEND_WRONG_PARAM_COUNT(); - } else if (zend_parse_parameters(argc, "rddlllss|a", &IM, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) { - return; - } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { + } else if (zend_parse_parameters(argc, "Oddlllss|a", &IM, gd_image_ce, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) { return; } + im = php_gd_image_ptr_from_zval_p(IM); } /* convert angle to radians */ @@ -3408,12 +3456,10 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int #define PHP_GD_SINGLE_RES \ zval *SIM; \ gdImagePtr im_src; \ - if (zend_parse_parameters(1, "r", &SIM) == FAILURE) { \ + if (zend_parse_parameters(1, "O", &SIM, gd_image_ce) == FAILURE) { \ return; \ } \ - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { \ - return; \ - } + im_src = php_gd_image_ptr_from_zval_p(SIM); static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS) { @@ -3443,13 +3489,11 @@ static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS) gdImagePtr im_src; zend_long brightness, tmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zll", &SIM, &tmp, &brightness) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oll", &SIM, gd_image_ce, &tmp, &brightness) == FAILURE) { return; } - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_src = php_gd_image_ptr_from_zval_p(SIM); if (gdImageBrightness(im_src, (int)brightness) == 1) { RETURN_TRUE; @@ -3464,13 +3508,11 @@ static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS) gdImagePtr im_src; zend_long contrast, tmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rll", &SIM, &tmp, &contrast) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oll", &SIM, gd_image_ce, &tmp, &contrast) == FAILURE) { return; } - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_src = php_gd_image_ptr_from_zval_p(SIM); if (gdImageContrast(im_src, (int)contrast) == 1) { RETURN_TRUE; @@ -3486,13 +3528,11 @@ static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS) zend_long r,g,b,tmp; zend_long a = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllll|l", &SIM, &tmp, &r, &g, &b, &a) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ollll|l", &SIM, gd_image_ce, &tmp, &r, &g, &b, &a) == FAILURE) { return; } - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_src = php_gd_image_ptr_from_zval_p(SIM); if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) { RETURN_TRUE; @@ -3563,13 +3603,11 @@ static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS) gdImagePtr im_src; double weight; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rld", &SIM, &tmp, &weight) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Old", &SIM, gd_image_ce, &tmp, &weight) == FAILURE) { return; } - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_src = php_gd_image_ptr_from_zval_p(SIM); if (gdImageSmooth(im_src, (float)weight)==1) { RETURN_TRUE; @@ -3585,13 +3623,11 @@ static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS) zend_long tmp, blocksize; zend_bool mode = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rll|b", &IM, &tmp, &blocksize, &mode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oll|b", &IM, gd_image_ce, &tmp, &blocksize, &mode) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) { RETURN_TRUE; @@ -3608,13 +3644,11 @@ static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS) zend_long tmp; zend_long scatter_sub, scatter_plus; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlll|a", &IM, &tmp, &scatter_sub, &scatter_plus, &hash_colors) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olll|a", &IM, gd_image_ce, &tmp, &scatter_sub, &scatter_plus, &hash_colors) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (hash_colors) { uint32_t i = 0; @@ -3667,7 +3701,7 @@ PHP_FUNCTION(imagefilter) if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > IMAGE_FILTER_MAX_ARGS) { WRONG_PARAM_COUNT; - } else if (zend_parse_parameters(2, "rl", &tmp, &filtertype) == FAILURE) { + } else if (zend_parse_parameters(2, "Ol", &tmp, gd_image_ce, &filtertype) == FAILURE) { return; } @@ -3688,13 +3722,11 @@ PHP_FUNCTION(imageconvolution) int nelem, i, j, res; float matrix[3][3] = {{0,0,0}, {0,0,0}, {0,0,0}}; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "radd", &SIM, &hash_matrix, &div, &offset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oadd", &SIM, gd_image_ce, &hash_matrix, &div, &offset) == FAILURE) { return; } - if ((im_src = (gdImagePtr)zend_fetch_resource(Z_RES_P(SIM), "Image", le_gd)) == NULL) { - return; - } + im_src = php_gd_image_ptr_from_zval_p(SIM); nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix)); if (nelem != 3) { @@ -3738,13 +3770,11 @@ PHP_FUNCTION(imageflip) zend_long mode; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &IM, &mode) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &IM, gd_image_ce, &mode) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); switch (mode) { case GD_FLIP_VERTICAL: @@ -3776,14 +3806,11 @@ PHP_FUNCTION(imageantialias) zend_bool alias; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rb", &IM, &alias) == FAILURE) { - return; - } - - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ob", &IM, gd_image_ce, &alias) == FAILURE) { return; } + im = php_gd_image_ptr_from_zval_p(IM); if (im->trueColor) { im->AA = alias; } @@ -3803,13 +3830,11 @@ PHP_FUNCTION(imagecrop) zval *z_rect; zval *tmp; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra", &IM, &z_rect) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &z_rect) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) { rect.x = zval_get_long(tmp); @@ -3843,9 +3868,10 @@ PHP_FUNCTION(imagecrop) if (im_crop == NULL) { RETURN_FALSE; - } else { - RETURN_RES(zend_register_resource(im_crop, le_gd)); } + + + RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop)); } /* }}} */ @@ -3860,13 +3886,11 @@ PHP_FUNCTION(imagecropauto) gdImagePtr im; gdImagePtr im_crop; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|ldl", &IM, &mode, &threshold, &color) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ldl", &IM, gd_image_ce, &mode, &threshold, &color) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); switch (mode) { case GD_CROP_DEFAULT: @@ -3892,9 +3916,9 @@ PHP_FUNCTION(imagecropauto) if (im_crop == NULL) { RETURN_FALSE; - } else { - RETURN_RES(zend_register_resource(im_crop, le_gd)); } + + RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop)); } /* }}} */ @@ -3909,14 +3933,12 @@ PHP_FUNCTION(imagescale) zend_long tmp_w, tmp_h=-1, tmp_m = GD_BILINEAR_FIXED; gdInterpolationMethod method, old_method; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|ll", &IM, &tmp_w, &tmp_h, &tmp_m) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|ll", &IM, gd_image_ce, &tmp_w, &tmp_h, &tmp_m) == FAILURE) { return; } method = tmp_m; - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (tmp_h < 0 || tmp_w < 0) { /* preserve ratio */ @@ -3949,9 +3971,9 @@ PHP_FUNCTION(imagescale) if (im_scaled == NULL) { RETURN_FALSE; - } else { - RETURN_RES(zend_register_resource(im_scaled, le_gd)); } + + RETURN_OBJ(gd_ext_image_object_init(return_value, im_scaled)); } /* }}} */ @@ -3971,13 +3993,11 @@ PHP_FUNCTION(imageaffine) int i, nelems; zval *zval_affine_elem = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra|a", &IM, &z_affine, &z_rect) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa|a", &IM, gd_image_ce, &z_affine, &z_rect) == FAILURE) { return; } - if ((src = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + src = php_gd_image_ptr_from_zval_p(IM); if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) { zend_value_error("Affine array must have six elements"); @@ -4046,9 +4066,9 @@ PHP_FUNCTION(imageaffine) if (dst == NULL) { RETURN_FALSE; - } else { - RETURN_RES(zend_register_resource(dst, le_gd)); } + + RETURN_OBJ(gd_ext_image_object_init(return_value, dst)); } /* }}} */ @@ -4210,13 +4230,11 @@ PHP_FUNCTION(imagesetinterpolation) gdImagePtr im; zend_long method = GD_BILINEAR_FIXED; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &IM, &method) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l", &IM, gd_image_ce, &method) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); if (method == -1) { method = GD_BILINEAR_FIXED; @@ -4233,13 +4251,11 @@ PHP_FUNCTION(imageresolution) gdImagePtr im; zend_long res_x = GD_RESOLUTION, res_y = GD_RESOLUTION; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|ll", &IM, &res_x, &res_y) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|ll", &IM, gd_image_ce, &res_x, &res_y) == FAILURE) { return; } - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { - return; - } + im = php_gd_image_ptr_from_zval_p(IM); switch (ZEND_NUM_ARGS()) { case 3: diff --git a/ext/gd/gd.stub.php b/ext/gd/gd.stub.php index 75d0916751bcd..addffb1433920 100644 --- a/ext/gd/gd.stub.php +++ b/ext/gd/gd.stub.php @@ -10,39 +10,39 @@ function imagesetstyle($im, array $styles): bool {} /** @return resource|false */ function imagecreatetruecolor(int $x_size, int $y_size) {} -function imageistruecolor($im): bool {} +function imageistruecolor(GdImage $im): bool {} -function imagetruecolortopalette($im, bool $ditherFlag, int $colorWanted): bool {} +function imagetruecolortopalette(GdImage $im, bool $ditherFlag, int $colorWanted): bool {} -function imagepalettetotruecolor($im): bool {} +function imagepalettetotruecolor(GdImage $im): bool {} function imagecolormatch($im1, $im2): bool {} -function imagesetthickness($im, int $thickness): bool {} +function imagesetthickness(GdImage $im, int $thickness): bool {} -function imagefilledellipse($im, int $cx, int $cy, int $w, int $h, int $color): bool {} +function imagefilledellipse(GdImage $im, int $cx, int $cy, int $w, int $h, int $color): bool {} -function imagefilledarc($im, int $cx, int $cy, int $w, int $h, int $s, int $e, int $col, int $style): bool {} +function imagefilledarc(GdImage $im, int $cx, int $cy, int $w, int $h, int $s, int $e, int $col, int $style): bool {} -function imagealphablending($im, bool $blend): bool {} +function imagealphablending(GdImage $im, bool $blend): bool {} -function imagesavealpha($im, bool $save): bool {} +function imagesavealpha(GdImage $im, bool $save): bool {} -function imagelayereffect($im, int $effect): bool {} +function imagelayereffect(GdImage $im, int $effect): bool {} /** @return int|false */ -function imagecolorallocatealpha($im, int $red, int $green, int $blue, int $alpha) {} +function imagecolorallocatealpha(GdImage $im, int $red, int $green, int $blue, int $alpha) {} /** @return int|false */ -function imagecolorresolvealpha($im, int $red, int $green, int $blue, int $alpha) {} +function imagecolorresolvealpha(GdImage $im, int $red, int $green, int $blue, int $alpha) {} /** @return int|false */ -function imagecolorclosestalpha($im, int $red, int $green, int $blue, int $alpha) {} +function imagecolorclosestalpha(GdImage $im, int $red, int $green, int $blue, int $alpha) {} /** @return int|false */ -function imagecolorexactalpha($im, int $red, int $green, int $blue, int $alpha) {} +function imagecolorexactalpha(GdImage $im, int $red, int $green, int $blue, int $alpha) {} -function imagecopyresampled($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h): bool {} +function imagecopyresampled(GdImage $dst_im, GdImage $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h): bool {} #ifdef PHP_WIN32 @@ -55,11 +55,11 @@ function imagegrabscreen() {} #endif /** @return resource|false */ -function imagerotate($im, float $angle, int $bgdcolor, int $ignoretransparent = 0) {} +function imagerotate(GdImage $im, float $angle, int $bgdcolor, int $ignoretransparent = 0) {} -function imagesettile($im, $tile): bool {} +function imagesettile(GdImage $im, $tile): bool {} -function imagesetbrush($im, $brush): bool {} +function imagesetbrush(GdImage $im, $brush): bool {} /** @return resource|false */ function imagecreate(int $x_size, int $y_size) {} @@ -117,152 +117,152 @@ function imagecreatefrombmp(string $filename) {} function imagecreatefromtga(string $filename) {} #endif -function imagexbm($im, ?string $filename, int $foreground = UNKNOWN): bool {} +function imagexbm(GdImage $im, ?string $filename, int $foreground = UNKNOWN): bool {} -function imagegif($im, $to = NULL): bool {} +function imagegif(GdImage $im, $to = NULL): bool {} #ifdef HAVE_GD_PNG -function imagepng($im, $to = NULL, int $quality = UNKNOWN, int $filters = UNKNOWN): bool {} +function imagepng(GdImage $im, $to = NULL, int $quality = UNKNOWN, int $filters = UNKNOWN): bool {} #endif #ifdef HAVE_GD_WEBP -function imagewebp($im, $to = NULL, int $quality = UNKNOWN): bool {} +function imagewebp(GdImage $im, $to = NULL, int $quality = UNKNOWN): bool {} #endif #ifdef HAVE_GD_JPG -function imagejpeg($im, $to = NULL, int $quality = UNKNOWN): bool {} +function imagejpeg(GdImage $im, $to = NULL, int $quality = UNKNOWN): bool {} #endif -function imagewbmp($im, $to = NULL, int $foreground = UNKNOWN): bool {} +function imagewbmp(GdImage $im, $to = NULL, int $foreground = UNKNOWN): bool {} -function imagegd($im, $to = UNKNOWN): bool {} +function imagegd(GdImage $im, $to = UNKNOWN): bool {} -function imagegd2($im, $to = UNKNOWN, int $chunk_size = UNKNOWN, int $type = UNKNOWN): bool {} +function imagegd2(GdImage $im, $to = UNKNOWN, int $chunk_size = UNKNOWN, int $type = UNKNOWN): bool {} #ifdef HAVE_GD_BMP -function imagebmp($im, $to = NULL, int $compressed = 1): bool {} +function imagebmp(GdImage $im, $to = NULL, int $compressed = 1): bool {} #endif -function imagedestroy($im): bool {} +function imagedestroy(GdImage $im): bool {} /** @return int|false */ -function imagecolorallocate($im, int $red, int $green, int $blue) {} +function imagecolorallocate(GdImage $im, int $red, int $green, int $blue) {} -function imagepalettecopy($dst, $src): void {} +function imagepalettecopy(GdImage $dst, GdImage $src): void {} /** @return int|false */ -function imagecolorat($im, int $x, int $y) {} +function imagecolorat(GdImage $im, int $x, int $y) {} /** @return int|false */ -function imagecolorclosest($im, int $red, int $green, int $blue) {} +function imagecolorclosest(GdImage $im, int $red, int $green, int $blue) {} /** @return int|false */ -function imagecolorclosesthwb($im, int $red, int $green, int $blue) {} +function imagecolorclosesthwb(GdImage $im, int $red, int $green, int $blue) {} -function imagecolordeallocate($im, int $index): bool {} +function imagecolordeallocate(GdImage $im, int $index): bool {} /** @return int|false */ -function imagecolorresolve($im, int $red, int $green, int $blue) {} +function imagecolorresolve(GdImage $im, int $red, int $green, int $blue) {} /** @return int|false */ -function imagecolorexact($im, int $red, int $green, int $blue) {} +function imagecolorexact(GdImage $im, int $red, int $green, int $blue) {} /** @return ?false */ -function imagecolorset($im, int $color, int $red, int $green, int $blue, int $alpha = 0) {} +function imagecolorset(GdImage $im, int $color, int $red, int $green, int $blue, int $alpha = 0) {} /** @return array|false */ -function imagecolorsforindex($im, int $index) {} +function imagecolorsforindex(GdImage $im, int $index) {} -function imagegammacorrect($im, float $inputgamma, float $outputgamma): bool {} +function imagegammacorrect(GdImage $im, float $inputgamma, float $outputgamma): bool {} -function imagesetpixel($im, int $x, int $y, int $col): bool {} +function imagesetpixel(GdImage $im, int $x, int $y, int $col): bool {} -function imageline($im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} +function imageline(GdImage $im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} -function imagedashedline($im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} +function imagedashedline(GdImage $im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} -function imagerectangle($im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} +function imagerectangle(GdImage $im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} -function imagefilledrectangle($im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} +function imagefilledrectangle(GdImage $im, int $x1, int $y1, int $x2, int $y2, int $col): bool {} -function imagearc($im, int $cx, int $cy, int $w, int $h, int $s, int $e, int $col): bool {} +function imagearc(GdImage $im, int $cx, int $cy, int $w, int $h, int $s, int $e, int $col): bool {} -function imageellipse($im, int $cx, int $cy, int $w, int $h, int $color): bool {} +function imageellipse(GdImage $im, int $cx, int $cy, int $w, int $h, int $color): bool {} -function imagefilltoborder($im, int $x, int $y, int $border, int $col): bool {} +function imagefilltoborder(GdImage $im, int $x, int $y, int $border, int $col): bool {} -function imagefill($im, int $x, int $y, int $col): bool {} +function imagefill(GdImage $im, int $x, int $y, int $col): bool {} -function imagecolorstotal($im): int {} +function imagecolorstotal(GdImage $im): int {} -function imagecolortransparent($im, int $col = UNKNOWN): ?int {} +function imagecolortransparent(GdImage $im, int $col = UNKNOWN): ?int {} -function imageinterlace($im, int $interlace = UNKNOWN): ?int {} +function imageinterlace(GdImage $im, int $interlace = UNKNOWN): ?int {} -function imagepolygon($im, array $points, int $num_pos, int $col): bool {} +function imagepolygon(GdImage $im, array $points, int $num_pos, int $col): bool {} -function imageopenpolygon($im, array $points, int $num_pos, int $col): bool {} +function imageopenpolygon(GdImage $im, array $points, int $num_pos, int $col): bool {} -function imagefilledpolygon($im, array $points, int $num_pos, int $col): bool {} +function imagefilledpolygon(GdImage $im, array $points, int $num_pos, int $col): bool {} function imagefontwidth(int $font): int {} function imagefontheight(int $font): int {} -function imagechar($im, int $font, int $x, int $y, string $c, int $col): bool {} +function imagechar(GdImage $im, int $font, int $x, int $y, string $c, int $col): bool {} -function imagecharup($im, int $font, int $x, int $y, string $c, int $col): bool {} +function imagecharup(GdImage $im, int $font, int $x, int $y, string $c, int $col): bool {} -function imagestring($im, int $font, int $x, int $y, string $str, int $col): bool {} +function imagestring(GdImage $im, int $font, int $x, int $y, string $str, int $col): bool {} function imagestringup($im, int $font, int $x, int $y, string $str, int $col): bool {} -function imagecopy($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h): bool {} +function imagecopy(GdImage $dst_im, GdImage $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h): bool {} -function imagecopymerge($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct): bool {} +function imagecopymerge(GdImage $dst_im, GdImage $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct): bool {} -function imagecopymergegray($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct): bool {} +function imagecopymergegray(GdImage $dst_im, GdImage $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h, int $pct): bool {} -function imagecopyresized($dst_im, $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h): bool {} +function imagecopyresized(GdImage $dst_im, GdImage $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_w, int $dst_h, int $src_w, int $src_h): bool {} -function imagesx($im): int {} +function imagesx(GdImage $im): int {} -function imagesy($im): int {} +function imagesy(GdImage $im): int {} -function imagesetclip($im, int $x1, int $x2, int $y1, int $y2): bool {} +function imagesetclip(GdImage $im, int $x1, int $x2, int $y1, int $y2): bool {} -function imagegetclip($im): array {} +function imagegetclip(GdImage $im): array {} #ifdef HAVE_GD_FREETYPE /** @return array|false */ function imageftbbox(float $size, float $angle, string $font_file, string $text, array $extrainfo = UNKNOWN) {} -function imagefttext($im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, array $extrainfo = UNKNOWN) {} +function imagefttext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text, array $extrainfo = UNKNOWN) {} function imagettfbbox(float $size, float $angle, string $font_file, string $text) {} -function imagettftext($im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text) {} +function imagettftext(GdImage $im, float $size, float $angle, int $x, int $y, int $col, string $font_file, string $text) {} #endif -function imagefilter($im, int $filtertype, $arg1 = UNKNOWN, $arg2 = UNKNOWN, $arg3 = UNKNOWN, $arg4 = UNKNOWN): bool {} +function imagefilter(GdImage $im, int $filtertype, $arg1 = UNKNOWN, $arg2 = UNKNOWN, $arg3 = UNKNOWN, $arg4 = UNKNOWN): bool {} -function imageconvolution($im, array $matrix3x3, float $div, float $offset): bool {} +function imageconvolution(GdImage $im, array $matrix3x3, float $div, float $offset): bool {} -function imageflip($im, int $mode): bool {} +function imageflip(GdImage $im, int $mode): bool {} -function imageantialias($im, bool $on): bool {} +function imageantialias(GdImage $im, bool $on): bool {} /** @return resource|false */ -function imagecrop($im, array $rect) {} +function imagecrop(GdImage $im, array $rect) {} /** @return resource|false */ -function imagecropauto($im, int $mode = IMG_CROP_DEFAULT, float $threshold = 0.5, int $color = -1) {} +function imagecropauto(GdImage $im, int $mode = IMG_CROP_DEFAULT, float $threshold = 0.5, int $color = -1) {} /** @return resource|false */ -function imagescale($im, int $new_width, int $new_height = UNKNOWN, int $mode = IMG_BILINEAR_FIXED) {} +function imagescale(GdImage $im, int $new_width, int $new_height = UNKNOWN, int $mode = IMG_BILINEAR_FIXED) {} /** @return resource|false */ -function imageaffine($im, array $affine, array $clip = UNKNOWN) {} +function imageaffine(GdImage $im, array $affine, array $clip = UNKNOWN) {} /** @return array|false */ function imageaffinematrixget(int $type, $options = UNKNOWN) {} @@ -270,7 +270,7 @@ function imageaffinematrixget(int $type, $options = UNKNOWN) {} /** @return array|false */ function imageaffinematrixconcat(array $m1, array $m2) {} -function imagesetinterpolation($im, int $method = IMG_BILENEAR_FIXED): bool {} +function imagesetinterpolation(GdImage $im, int $method = IMG_BILENEAR_FIXED): bool {} /** @return array|true */ -function imageresolution($im, int $res_x = UNKNOWN, int $res_y = UNKNOWN) {} +function imageresolution(GdImage $im, int $res_x = UNKNOWN, int $res_y = UNKNOWN) {} diff --git a/ext/gd/gd_arginfo.h b/ext/gd/gd_arginfo.h index 0544802c7ef3c..40639b46c6152 100644 --- a/ext/gd/gd_arginfo.h +++ b/ext/gd/gd_arginfo.h @@ -18,11 +18,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecreatetruecolor, 0, 0, 2) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imageistruecolor, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagetruecolortopalette, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, ditherFlag, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, colorWanted, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -35,12 +35,12 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecolormatch, 0, 2, _IS_BOOL, ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesetthickness, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, thickness, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilledellipse, 0, 6, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, cx, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, cy, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, w, IS_LONG, 0) @@ -49,7 +49,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilledellipse, 0, 6, _IS_BO ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilledarc, 0, 9, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, cx, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, cy, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, w, IS_LONG, 0) @@ -61,22 +61,22 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilledarc, 0, 9, _IS_BOOL, ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagealphablending, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, blend, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesavealpha, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, save, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagelayereffect, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, effect, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorallocatealpha, 0, 0, 5) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, red, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, green, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, blue, IS_LONG, 0) @@ -90,8 +90,8 @@ ZEND_END_ARG_INFO() #define arginfo_imagecolorexactalpha arginfo_imagecolorallocatealpha ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecopyresampled, 0, 10, _IS_BOOL, 0) - ZEND_ARG_INFO(0, dst_im) - ZEND_ARG_INFO(0, src_im) + ZEND_ARG_OBJ_INFO(0, dst_im, GdImage, 0) + ZEND_ARG_OBJ_INFO(0, src_im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, dst_x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, dst_y, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, src_x, IS_LONG, 0) @@ -115,19 +115,19 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_INFO_EX(arginfo_imagerotate, 0, 0, 3) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, bgdcolor, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, ignoretransparent, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesettile, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, tile) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesetbrush, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, brush) ZEND_END_ARG_INFO() @@ -195,19 +195,19 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagexbm, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 1) ZEND_ARG_TYPE_INFO(0, foreground, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegif, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, to) ZEND_END_ARG_INFO() #if defined(HAVE_GD_PNG) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagepng, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, to) ZEND_ARG_TYPE_INFO(0, quality, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, filters, IS_LONG, 0) @@ -216,7 +216,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_GD_WEBP) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagewebp, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, to) ZEND_ARG_TYPE_INFO(0, quality, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -224,14 +224,14 @@ ZEND_END_ARG_INFO() #if defined(HAVE_GD_JPG) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagejpeg, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, to) ZEND_ARG_TYPE_INFO(0, quality, IS_LONG, 0) ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagewbmp, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, to) ZEND_ARG_TYPE_INFO(0, foreground, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -239,7 +239,7 @@ ZEND_END_ARG_INFO() #define arginfo_imagegd arginfo_imagegif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegd2, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, to) ZEND_ARG_TYPE_INFO(0, chunk_size, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) @@ -247,7 +247,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_GD_BMP) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagebmp, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_INFO(0, to) ZEND_ARG_TYPE_INFO(0, compressed, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -256,19 +256,19 @@ ZEND_END_ARG_INFO() #define arginfo_imagedestroy arginfo_imageistruecolor ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorallocate, 0, 0, 4) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, red, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, green, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, blue, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagepalettecopy, 0, 2, IS_VOID, 0) - ZEND_ARG_INFO(0, dst) - ZEND_ARG_INFO(0, src) + ZEND_ARG_OBJ_INFO(0, dst, GdImage, 0) + ZEND_ARG_OBJ_INFO(0, src, GdImage, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorat, 0, 0, 3) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -278,7 +278,7 @@ ZEND_END_ARG_INFO() #define arginfo_imagecolorclosesthwb arginfo_imagecolorallocate ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecolordeallocate, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -287,7 +287,7 @@ ZEND_END_ARG_INFO() #define arginfo_imagecolorexact arginfo_imagecolorallocate ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorset, 0, 0, 5) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, color, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, red, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, green, IS_LONG, 0) @@ -296,25 +296,25 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorset, 0, 0, 5) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorsforindex, 0, 0, 2) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegammacorrect, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, inputgamma, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, outputgamma, IS_DOUBLE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesetpixel, 0, 4, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imageline, 0, 6, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, x1, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, y1, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, x2, IS_LONG, 0) @@ -329,7 +329,7 @@ ZEND_END_ARG_INFO() #define arginfo_imagefilledrectangle arginfo_imageline ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagearc, 0, 8, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, cx, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, cy, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, w, IS_LONG, 0) @@ -342,7 +342,7 @@ ZEND_END_ARG_INFO() #define arginfo_imageellipse arginfo_imagefilledellipse ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilltoborder, 0, 5, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, border, IS_LONG, 0) @@ -352,21 +352,21 @@ ZEND_END_ARG_INFO() #define arginfo_imagefill arginfo_imagesetpixel ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecolorstotal, 0, 1, IS_LONG, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecolortransparent, 0, 1, IS_LONG, 1) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imageinterlace, 0, 1, IS_LONG, 1) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, interlace, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagepolygon, 0, 4, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, points, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, num_pos, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0) @@ -383,7 +383,7 @@ ZEND_END_ARG_INFO() #define arginfo_imagefontheight arginfo_imagefontwidth ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagechar, 0, 6, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, font, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0) @@ -394,7 +394,7 @@ ZEND_END_ARG_INFO() #define arginfo_imagecharup arginfo_imagechar ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagestring, 0, 6, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, font, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0) @@ -402,11 +402,18 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagestring, 0, 6, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_imagestringup arginfo_imagestring +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagestringup, 0, 6, _IS_BOOL, 0) + ZEND_ARG_INFO(0, im) + ZEND_ARG_TYPE_INFO(0, font, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0) +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecopy, 0, 8, _IS_BOOL, 0) - ZEND_ARG_INFO(0, dst_im) - ZEND_ARG_INFO(0, src_im) + ZEND_ARG_OBJ_INFO(0, dst_im, GdImage, 0) + ZEND_ARG_OBJ_INFO(0, src_im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, dst_x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, dst_y, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, src_x, IS_LONG, 0) @@ -416,8 +423,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecopy, 0, 8, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecopymerge, 0, 9, _IS_BOOL, 0) - ZEND_ARG_INFO(0, dst_im) - ZEND_ARG_INFO(0, src_im) + ZEND_ARG_OBJ_INFO(0, dst_im, GdImage, 0) + ZEND_ARG_OBJ_INFO(0, src_im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, dst_x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, dst_y, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, src_x, IS_LONG, 0) @@ -436,7 +443,7 @@ ZEND_END_ARG_INFO() #define arginfo_imagesy arginfo_imagecolorstotal ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesetclip, 0, 5, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, x1, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, x2, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, y1, IS_LONG, 0) @@ -444,7 +451,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesetclip, 0, 5, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagegetclip, 0, 1, IS_ARRAY, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_END_ARG_INFO() #if defined(HAVE_GD_FREETYPE) @@ -459,7 +466,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_GD_FREETYPE) ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefttext, 0, 0, 8) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) @@ -482,7 +489,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_GD_FREETYPE) ZEND_BEGIN_ARG_INFO_EX(arginfo_imagettftext, 0, 0, 8) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, size, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, angle, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) @@ -494,7 +501,7 @@ ZEND_END_ARG_INFO() #endif ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilter, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, filtertype, IS_LONG, 0) ZEND_ARG_INFO(0, arg1) ZEND_ARG_INFO(0, arg2) @@ -503,43 +510,43 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagefilter, 0, 2, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imageconvolution, 0, 4, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, matrix3x3, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, div, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, offset, IS_DOUBLE, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imageflip, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imageantialias, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, on, _IS_BOOL, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecrop, 0, 0, 2) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, rect, IS_ARRAY, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecropauto, 0, 0, 1) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, threshold, IS_DOUBLE, 0) ZEND_ARG_TYPE_INFO(0, color, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imagescale, 0, 0, 2) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, new_width, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, new_height, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imageaffine, 0, 0, 2) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, affine, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, clip, IS_ARRAY, 0) ZEND_END_ARG_INFO() @@ -555,12 +562,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imageaffinematrixconcat, 0, 0, 2) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesetinterpolation, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_imageresolution, 0, 0, 1) - ZEND_ARG_INFO(0, im) + ZEND_ARG_OBJ_INFO(0, im, GdImage, 0) ZEND_ARG_TYPE_INFO(0, res_x, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, res_y, IS_LONG, 0) ZEND_END_ARG_INFO() diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c deleted file mode 100644 index 52265de4ba21d..0000000000000 --- a/ext/gd/gd_ctx.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Stanislav Malyshev | - +----------------------------------------------------------------------+ - */ - -#include "php_gd.h" - -#define CTX_PUTC(c,ctx) ctx->putC(ctx, c) - -static void _php_image_output_putc(struct gdIOCtx *ctx, int c) /* {{{ */ -{ - /* without the following downcast, the write will fail - * (i.e., will write a zero byte) for all - * big endian architectures: - */ - unsigned char ch = (unsigned char) c; - php_write(&ch, 1); -} /* }}} */ - -static int _php_image_output_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ -{ - return php_write((void *)buf, l); -} /* }}} */ - -static void _php_image_output_ctxfree(struct gdIOCtx *ctx) /* {{{ */ -{ - if(ctx) { - efree(ctx); - } -} /* }}} */ - -static void _php_image_stream_putc(struct gdIOCtx *ctx, int c) /* {{{ */ { - char ch = (char) c; - php_stream * stream = (php_stream *)ctx->data; - php_stream_write(stream, &ch, 1); -} /* }}} */ - -static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ -{ - php_stream * stream = (php_stream *)ctx->data; - return php_stream_write(stream, (void *)buf, l); -} /* }}} */ - -static void _php_image_stream_ctxfree(struct gdIOCtx *ctx) /* {{{ */ -{ - if(ctx->data) { - ctx->data = NULL; - } - if(ctx) { - efree(ctx); - } -} /* }}} */ - -static void _php_image_stream_ctxfreeandclose(struct gdIOCtx *ctx) /* {{{ */ -{ - - if(ctx->data) { - php_stream_close((php_stream *) ctx->data); - ctx->data = NULL; - } - if(ctx) { - efree(ctx); - } -} /* }}} */ - -/* {{{ _php_image_output_ctx */ -static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) -{ - zval *imgind; - char *file = NULL; - size_t file_len = 0; - zend_long quality, basefilter; - zend_bool compressed = 1; - gdImagePtr im; - int argc = ZEND_NUM_ARGS(); - int q = -1, i; - int f = -1; - gdIOCtx *ctx = NULL; - zval *to_zval = NULL; - php_stream *stream; - int close_stream = 1; - - /* The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called - * from imagey(). - */ - switch (image_type) { - case PHP_GDIMG_TYPE_XBM: - if (zend_parse_parameters(argc, "rp!|ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) { - return; - } - break; - case PHP_GDIMG_TYPE_BMP: - if (zend_parse_parameters(argc, "r|z!b", &imgind, &to_zval, &compressed) == FAILURE) { - return; - } - break; - default: - /* PHP_GDIMG_TYPE_GIF - * PHP_GDIMG_TYPE_PNG - * PHP_GDIMG_TYPE_JPG - * PHP_GDIMG_TYPE_WBM - * PHP_GDIMG_TYPE_WEBP - * */ - if (zend_parse_parameters(argc, "r|z!ll", &imgind, &to_zval, &quality, &basefilter) == FAILURE) { - return; - } - } - - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(imgind), "Image", phpi_get_le_gd())) == NULL) { - return; - } - - if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3) { - q = quality; /* or colorindex for foreground of BW images (defaults to black) */ - if (argc == 4) { - f = basefilter; - } - } - - if (argc > 1 && to_zval != NULL) { - if (Z_TYPE_P(to_zval) == IS_RESOURCE) { - php_stream_from_zval_no_verify(stream, to_zval); - if (stream == NULL) { - RETURN_FALSE; - } - close_stream = 0; - } else if (Z_TYPE_P(to_zval) == IS_STRING) { - if (CHECK_ZVAL_NULL_PATH(to_zval)) { - zend_type_error("Invalid 2nd parameter, filename must not contain null bytes"); - return; - } - - stream = php_stream_open_wrapper(Z_STRVAL_P(to_zval), "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); - if (stream == NULL) { - RETURN_FALSE; - } - } else { - php_error_docref(NULL, E_WARNING, "Invalid 2nd parameter, it must a filename or a stream"); - RETURN_FALSE; - } - } else if (argc > 1 && file != NULL) { - stream = php_stream_open_wrapper(file, "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); - if (stream == NULL) { - RETURN_FALSE; - } - } else { - ctx = ecalloc(1, sizeof(gdIOCtx)); - ctx->putC = _php_image_output_putc; - ctx->putBuf = _php_image_output_putbuf; - ctx->gd_free = _php_image_output_ctxfree; - } - - if (!ctx) { - ctx = ecalloc(1, sizeof(gdIOCtx)); - ctx->putC = _php_image_stream_putc; - ctx->putBuf = _php_image_stream_putbuf; - if (close_stream) { - ctx->gd_free = _php_image_stream_ctxfreeandclose; - } else { - ctx->gd_free = _php_image_stream_ctxfree; - } - ctx->data = (void *)stream; - } - - switch(image_type) { - case PHP_GDIMG_TYPE_JPG: - (*func_p)(im, ctx, q); - break; - case PHP_GDIMG_TYPE_WEBP: - if (q == -1) { - q = 80; - } - (*func_p)(im, ctx, q); - break; - case PHP_GDIMG_TYPE_PNG: - (*func_p)(im, ctx, q, f); - break; - case PHP_GDIMG_TYPE_XBM: - case PHP_GDIMG_TYPE_WBM: - if (argc < 3) { - for(i=0; i < gdImageColorsTotal(im); i++) { - if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; - } - q = i; - } - if (image_type == PHP_GDIMG_TYPE_XBM) { - (*func_p)(im, file ? file : "", q, ctx); - } else { - (*func_p)(im, q, ctx); - } - break; - case PHP_GDIMG_TYPE_BMP: - (*func_p)(im, ctx, (int) compressed); - break; - default: - (*func_p)(im, ctx); - break; - } - - ctx->gd_free(ctx); - - RETURN_TRUE; -} -/* }}} */ diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c new file mode 100644 index 0000000000000..1978767b8ef12 --- /dev/null +++ b/ext/gd/gd_image_object.c @@ -0,0 +1,73 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Mark Randall | + +----------------------------------------------------------------------+ + */ + +#include "gd_image_object.h" + +static zend_object_handlers php_gd_image_object_handlers; + +static const zend_function_entry gd_image_object_methods[] = { + PHP_FE_END +}; + +static zend_always_inline php_gd_image_object* php_gd_image_object_from_ptr(zend_object* obj) { + return (php_gd_image_object *)((char *)(obj) - XtOffsetOf(php_gd_image_object, std)); +} + +static zend_object* php_gd_image_object_create(zend_class_entry * class_type) { + php_gd_image_object* intern = emalloc(sizeof(php_gd_image_object) + zend_object_properties_size(class_type)); + memset(intern, 0, sizeof(php_gd_image_object)); + + zend_object_std_init(&intern->std, class_type); + object_properties_init(&intern->std, class_type); + intern->std.handlers = &php_gd_image_object_handlers; + + return &intern->std; +}; + +static void php_gd_image_object_free(zend_object* intern) { + php_gd_image_object* img_obj_ptr = php_gd_image_object_from_ptr(intern); + gdImageDestroy(img_obj_ptr->image); + img_obj_ptr->image = NULL; + zend_object_std_dtor(intern); +}; + +static void php_gd_image_object_from_gd_ptr(zval* val, gdImagePtr image) { + object_init_ex(val, gd_image_ce); + php_gd_image_object_from_ptr(Z_OBJ_P(val))->image = image; + return Z_OBJ_P(val); +} + +static zend_function *php_gd_image_object_get_constructor(zend_object *object) { + zend_throw_error(NULL, "Directly constructing a GdImage object is prohibited"); + return NULL; +} + +static void php_gd_object_minit_helper() { + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "GdImage", gd_image_object_methods); + gd_image_ce = zend_register_internal_class(&ce); + gd_image_ce->ce_flags |= ZEND_ACC_FINAL; + gd_image_ce->create_object = php_gd_image_object_create; + + /* setting up the object handlers for the GdImage class */ + memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); + php_gd_image_object_handlers.clone_obj = NULL; + php_gd_image_object_handlers.free_obj = php_gd_image_object_free; + php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; + php_gd_image_object_handlers.offset = XtOffsetOf(php_gd_image_object, std); +} \ No newline at end of file diff --git a/ext/gd/gd_image_object.h b/ext/gd/gd_image_object.h new file mode 100644 index 0000000000000..7409a17119368 --- /dev/null +++ b/ext/gd/gd_image_object.h @@ -0,0 +1,36 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Mark Randall | + +----------------------------------------------------------------------+ + */ + +#ifndef SRC_GD_IMAGE_OBJECT_H +#define SRC_GD_IMAGE_OBJECT_H + +#include +#include + +zend_class_entry *gd_image_ce; + +typedef struct _gd_ext_image_object { + gdImagePtr image; + zend_object std; +} php_gd_image_object; + +static void php_gd_object_minit_helper(); +static zend_always_inline gdImagePtr php_gd_image_ptr_from_zval_p(zval*); +static void php_gd_image_object_from_gd_ptr(zval* val, gdImagePtr image); + +#endif //SRC_GD_IMAGE_OBJECT_H diff --git a/ext/gd/php_gd.h b/ext/gd/php_gd.h index a74a7cc6c2f1c..5a019b716f25c 100644 --- a/ext/gd/php_gd.h +++ b/ext/gd/php_gd.h @@ -29,6 +29,7 @@ RETURN_FALSE; \ } + #define PHP_GDIMG_TYPE_GIF 1 #define PHP_GDIMG_TYPE_PNG 2 #define PHP_GDIMG_TYPE_JPG 3 diff --git a/ext/gd/tests/bug41442.phpt b/ext/gd/tests/bug41442.phpt index 5c590deb77e3b..351734931accc 100644 --- a/ext/gd/tests/bug41442.phpt +++ b/ext/gd/tests/bug41442.phpt @@ -31,7 +31,9 @@ var_dump(imagecreatefromstring($str2)); echo "Done\n"; ?> ---EXPECTF-- -resource(%d) of type (gd) -resource(%d) of type (gd) +--EXPECT-- +object(GdImage)#2 (0) { +} +object(GdImage)#2 (0) { +} Done diff --git a/ext/gd/tests/bug66356.phpt b/ext/gd/tests/bug66356.phpt index 7dbfb1b40e177..0e13bca9b3957 100644 --- a/ext/gd/tests/bug66356.phpt +++ b/ext/gd/tests/bug66356.phpt @@ -28,8 +28,10 @@ var_dump(imagecrop($img, array("x" => 0x7fffff00, "y" => 0, "width" => 10, "heig var_dump(imagecrop($img, array("x" => 0, "y" => 0, "width" => 65535, "height" => 65535))); ?> --EXPECTF-- -resource(%d) of type (gd) -resource(%d) of type (gd) +object(GdImage)#2 (0) { +} +object(GdImage)#2 (0) { +} Array ( [x] => a @@ -39,11 +41,13 @@ Array ) Warning: imagecrop(): one parameter to a memory allocation multiplication is negative or zero, failing operation gracefully - in %sbug66356.php on line %d + in %s on line %d bool(false) -resource(%d) of type (gd) -resource(%d) of type (gd) +object(GdImage)#2 (0) { +} +object(GdImage)#2 (0) { +} Warning: imagecrop(): product of memory allocation multiplication would exceed INT_MAX, failing operation gracefully - in %sbug66356.php on line %d + in %s on line %d bool(false) diff --git a/ext/gd/tests/bug70976.phpt b/ext/gd/tests/bug70976.phpt index b4f5c9b78b6b8..cd10a8ffc03d8 100644 --- a/ext/gd/tests/bug70976.phpt +++ b/ext/gd/tests/bug70976.phpt @@ -10,4 +10,5 @@ $img = imagerotate(imagecreate(10,10),45,0x7ffffff9); var_dump($img); ?> --EXPECT-- -resource(5) of type (gd) +object(GdImage)#2 (0) { +} diff --git a/ext/gd/tests/bug73968.phpt b/ext/gd/tests/bug73968.phpt index 2211840f581b5..c1101c61bf06a 100644 --- a/ext/gd/tests/bug73968.phpt +++ b/ext/gd/tests/bug73968.phpt @@ -9,7 +9,6 @@ if (!extension_loaded('gd')) die('skip gd extension not available'); $im = imagecreatefromxbm(__DIR__ . DIRECTORY_SEPARATOR . 'bug73968.xbm'); var_dump($im); ?> -===DONE=== ---EXPECTF-- -resource(%d) of type (gd) -===DONE=== +--EXPECT-- +object(GdImage)#1 (0) { +} diff --git a/ext/gd/tests/bug74435.phpt b/ext/gd/tests/bug74435.phpt index 9d11eb3839f2d..78f2103247a89 100644 --- a/ext/gd/tests/bug74435.phpt +++ b/ext/gd/tests/bug74435.phpt @@ -21,7 +21,6 @@ for ($i = 0; $i < $width; $i += 16) { } } ?> -===DONE=== ---EXPECTF-- -resource(%d) of type (gd) -===DONE=== +--EXPECT-- +object(GdImage)#1 (0) { +} diff --git a/ext/gd/tests/bug77269.phpt b/ext/gd/tests/bug77269.phpt index c89f674b8a0e5..527f26c39704f 100644 --- a/ext/gd/tests/bug77269.phpt +++ b/ext/gd/tests/bug77269.phpt @@ -10,9 +10,8 @@ memory_limit=2G --FILE-- ===DONE=== --EXPECTF-- diff --git a/ext/gd/tests/bug77391.phpt b/ext/gd/tests/bug77391.phpt index aa76c1470eeef..fbfa8a8026ebd 100644 --- a/ext/gd/tests/bug77391.phpt +++ b/ext/gd/tests/bug77391.phpt @@ -9,7 +9,6 @@ if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<=')) die('skip upstrea -===DONE=== ---EXPECTF-- -resource(%d) of type (gd) -===DONE=== +--EXPECT-- +object(GdImage)#1 (0) { +} diff --git a/ext/gd/tests/gdimage_prevent_cloning.phpt b/ext/gd/tests/gdimage_prevent_cloning.phpt new file mode 100644 index 0000000000000..0f5c198e88b35 --- /dev/null +++ b/ext/gd/tests/gdimage_prevent_cloning.phpt @@ -0,0 +1,20 @@ +--TEST-- +Checks that GdImage instances cannot be cloned +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Error: Trying to clone an uncloneable object of class GdImage in %s:%d +Stack trace: +#0 {main} + thrown in %s on line %d diff --git a/ext/gd/tests/imageantialias_error1.phpt b/ext/gd/tests/imageantialias_error1.phpt deleted file mode 100644 index d74a2ad9a276c..0000000000000 --- a/ext/gd/tests/imageantialias_error1.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing wrong parameter resource in imageantialias() of GD library ---CREDITS-- -Guilherme Blanco -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imageantialias(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagechar_error2.phpt b/ext/gd/tests/imagechar_error2.phpt deleted file mode 100644 index a829282307ae5..0000000000000 --- a/ext/gd/tests/imagechar_error2.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing error on non-image resource parameter 1 of imagechar() of GD library ---CREDITS-- -Rafael Dohms -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -imagechar(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagecharup_error2.phpt b/ext/gd/tests/imagecharup_error2.phpt deleted file mode 100644 index f8b0bc4ebfa53..0000000000000 --- a/ext/gd/tests/imagecharup_error2.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing error on non-image resource parameter 1 of imagecharup() of GD library ---CREDITS-- -Rafael Dohms -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -imagecharup(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagecolorallocatealpha_error1.phpt b/ext/gd/tests/imagecolorallocatealpha_error1.phpt deleted file mode 100644 index ea490dd526d60..0000000000000 --- a/ext/gd/tests/imagecolorallocatealpha_error1.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Testing imagecolorallocatealpha(): Wrong types for parameter 1 ---CREDITS-- -Rafael Dohms ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imagecolorallocatealpha(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagecolordeallocate_error1.phpt b/ext/gd/tests/imagecolordeallocate_error1.phpt deleted file mode 100644 index 3c75055a5f2a8..0000000000000 --- a/ext/gd/tests/imagecolordeallocate_error1.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -Testing imagecolordeallocate() of GD library with invalid resource type ---CREDITS-- -Rafael Dohms -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -imagecolordeallocate(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagecolordeallocate_error3.phpt b/ext/gd/tests/imagecolordeallocate_error3.phpt index e9be1ea66a231..f81b52192ad7e 100644 --- a/ext/gd/tests/imagecolordeallocate_error3.phpt +++ b/ext/gd/tests/imagecolordeallocate_error3.phpt @@ -9,14 +9,17 @@ Rafael Dohms ?> --FILE-- imagecolordeallocate($image, $totalColors + 100) +); + ?> ---EXPECTF-- -Warning: imagecolordeallocate(): Color index 101 out of range in %s on line %d -bool(false) +--EXPECT-- +!! [ValueError] Color index 101 out of range diff --git a/ext/gd/tests/imagecolordeallocate_error4.phpt b/ext/gd/tests/imagecolordeallocate_error4.phpt index 22fc2fa3ef410..4d3009dcaef53 100644 --- a/ext/gd/tests/imagecolordeallocate_error4.phpt +++ b/ext/gd/tests/imagecolordeallocate_error4.phpt @@ -9,14 +9,17 @@ Rafael Dohms ?> --FILE-- imagecolordeallocate($image, -1.0) +); + ?> ---EXPECTF-- -Warning: imagecolordeallocate(): Color index -1 out of range in %s on line %d -bool(false) +--EXPECT-- +!! [ValueError] Color index -1 out of range diff --git a/ext/gd/tests/imagecolorstotal_error.phpt b/ext/gd/tests/imagecolorstotal_error.phpt deleted file mode 100644 index e05c6894dbf15..0000000000000 --- a/ext/gd/tests/imagecolorstotal_error.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -Test imagecolorstotal() function : error conditions - Pass invalid resource type ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -fclose($im); -?> -===DONE=== ---EXPECT-- -*** Testing imagecolorstotal() : error conditions *** - --- Testing imagecolorstotal() function with a invalid resource -imagecolorstotal(): supplied resource is not a valid Image resource -===DONE=== diff --git a/ext/gd/tests/imageellipse_error7.phpt b/ext/gd/tests/imageellipse_error7.phpt deleted file mode 100644 index bc78875d3dc6a..0000000000000 --- a/ext/gd/tests/imageellipse_error7.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -Testing wrong param passing imageellipse() of GD library ---CREDITS-- -Ivan Rosolen -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imageellipse(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagefilltoborder_error6.phpt b/ext/gd/tests/imagefilltoborder_error6.phpt deleted file mode 100644 index 5a77db798e708..0000000000000 --- a/ext/gd/tests/imagefilltoborder_error6.phpt +++ /dev/null @@ -1,31 +0,0 @@ ---TEST-- -Testing wrong param passing imagefilltoborder() of GD library ---CREDITS-- -Ivan Rosolen -#testfest PHPSP on 2009-06-30 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -imagefilltoborder(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagefilter_error10.phpt b/ext/gd/tests/imagefilter_error10.phpt deleted file mode 100644 index 07aecee632205..0000000000000 --- a/ext/gd/tests/imagefilter_error10.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing wrong parameter resource of EMBOSS in imagefilter() of GD library ---CREDITS-- -Guilherme Blanco -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imagefilter(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagegammacorrect_error2.phpt b/ext/gd/tests/imagegammacorrect_error2.phpt deleted file mode 100644 index 013dd67b9ae9a..0000000000000 --- a/ext/gd/tests/imagegammacorrect_error2.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing error with non-Image resource paramenter of imagegammacorrect() of GD library, ---CREDITS-- -Rafael Dohms -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -imagegammacorrect(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imageinterlace_error2.phpt b/ext/gd/tests/imageinterlace_error2.phpt deleted file mode 100644 index e906c61261f97..0000000000000 --- a/ext/gd/tests/imageinterlace_error2.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Testing resource that is not a image to imageinterlace() of GD library ---CREDITS-- -Edgar Ferreira da Silva -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imageinterlace(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imageistruecolor_error1.phpt b/ext/gd/tests/imageistruecolor_error1.phpt deleted file mode 100644 index b99dd93b001c8..0000000000000 --- a/ext/gd/tests/imageistruecolor_error1.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Testing imageistruecolor(): wrong parameters ---CREDITS-- -Rafael Dohms ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imageistruecolor(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagelayereffect_error3.phpt b/ext/gd/tests/imagelayereffect_error3.phpt deleted file mode 100644 index c3b793c45de82..0000000000000 --- a/ext/gd/tests/imagelayereffect_error3.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing imagelayereffect() with invalid resource of GD library ---CREDITS-- -Rafael Dohms -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imagelayereffect(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagepalettetotruecolor_basic.phpt b/ext/gd/tests/imagepalettetotruecolor_basic.phpt index 63a2b51e77d62..89fb514a5f430 100644 --- a/ext/gd/tests/imagepalettetotruecolor_basic.phpt +++ b/ext/gd/tests/imagepalettetotruecolor_basic.phpt @@ -9,7 +9,7 @@ Carlos André Ferrari --FILE-- ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imagepalettetotruecolor(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagerectangle_error2.phpt b/ext/gd/tests/imagerectangle_error2.phpt deleted file mode 100644 index fdc4678d57011..0000000000000 --- a/ext/gd/tests/imagerectangle_error2.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -Testing wrong param passing imagerectangle() of GD library ---CREDITS-- -Ivan Rosolen -#testfest PHPSP on 2009-06-30 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imagerectangle(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagesetthickness_error1.phpt b/ext/gd/tests/imagesetthickness_error1.phpt deleted file mode 100644 index a9ee7f9fcc00e..0000000000000 --- a/ext/gd/tests/imagesetthickness_error1.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Testing imagetruecolortopalette(): wrong types for first parameter ---CREDITS-- -Rafael Dohms ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imagesetthickness(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagestring_error2.phpt b/ext/gd/tests/imagestring_error2.phpt deleted file mode 100644 index ff9032a31248f..0000000000000 --- a/ext/gd/tests/imagestring_error2.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing error on non-image resource parameter 1 of imagestring() of GD library ---CREDITS-- -Rafael Dohms -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -imagestring(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagestringup_error2.phpt b/ext/gd/tests/imagestringup_error2.phpt deleted file mode 100644 index c09792c9823d6..0000000000000 --- a/ext/gd/tests/imagestringup_error2.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Testing error on non-image resource parameter 1 of imagestringup() of GD library ---CREDITS-- -Rafael Dohms -#testfest PHPSP on 2009-06-20 ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -imagestringup(): supplied resource is not a valid Image resource diff --git a/ext/gd/tests/imagetruecolortopalette_error1.phpt b/ext/gd/tests/imagetruecolortopalette_error1.phpt deleted file mode 100644 index dcdcfaea2023b..0000000000000 --- a/ext/gd/tests/imagetruecolortopalette_error1.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -Testing imagetruecolortopalette(): wrong parameters for parameter 1 ---CREDITS-- -Rafael Dohms ---SKIPIF-- - ---FILE-- -getMessage(), "\n"; -} -?> ---EXPECT-- -imagetruecolortopalette(): supplied resource is not a valid Image resource diff --git a/ext/posix/tests/posix_ttyname_error_wrongparams.phpt b/ext/posix/tests/posix_ttyname_error_wrongparams.phpt index 6dcb1d324de22..4ff7aaf3fe2f7 100644 --- a/ext/posix/tests/posix_ttyname_error_wrongparams.phpt +++ b/ext/posix/tests/posix_ttyname_error_wrongparams.phpt @@ -3,6 +3,7 @@ Test posix_ttyname() with wrong parameters --DESCRIPTION-- Gets the absolute path to the current terminal device that is open on a given file descriptor. Source code: ext/posix/posix.c + --CREDITS-- Falko Menge, mail at falko-menge dot de PHP Testfest Berlin 2009-05-10 @@ -11,18 +12,16 @@ PHP Testfest Berlin 2009-05-10 if (!extension_loaded('posix')) { die('SKIP - POSIX extension not available'); } - if (!extension_loaded('gd')) { - die('SKIP - GD extension not available'); - } - if (!function_exists('imagecreate')) { - die('SKIP - Function imagecreate() not available'); + + if (!function_exists('curl_init')) { + die('SKIP - Function curl_init() not available'); } ?> --FILE-- getMessage(), "\n"; } From 4f72f7e574f96a18741775a5be9a8758397806a4 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 24 Sep 2019 20:54:37 +0100 Subject: [PATCH 02/11] Split object file for later use --- ext/gd/config.m4 | 6 +- ext/gd/config.w32 | 1 + ext/gd/gd.c | 195 +++++++++++++++++++-------------------- ext/gd/gd_image_object.c | 36 ++++---- ext/gd/gd_image_object.h | 14 ++- 5 files changed, 127 insertions(+), 125 deletions(-) diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index 194687208d231..e0d4806f2ff4c 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -166,7 +166,7 @@ dnl Various checks for GD features PHP_GD_FREETYPE2 PHP_GD_JISX0208 - PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared,, \\$(GD_CFLAGS)) + PHP_NEW_EXTENSION(gd, gd.c gd_image_object.c $extra_sources, $ext_shared,, \\$(GD_CFLAGS)) PHP_ADD_BUILD_DIR($ext_builddir/libgd) GD_CFLAGS="-I$ext_srcdir/libgd $GD_CFLAGS" GD_HEADER_DIRS="ext/gd/ ext/gd/libgd/" @@ -183,7 +183,7 @@ dnl Various checks for GD features AC_DEFINE(HAVE_LIBGD, 1, [ ]) PHP_GD_CHECK_VERSION - PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared) + PHP_NEW_EXTENSION(gd, gd.c gd_image_object.c $extra_sources, $ext_shared) GD_HEADER_DIRS="ext/gd/" PHP_CHECK_LIBRARY(gd, gdImageCreate, [], [ AC_MSG_ERROR([GD build test failed. Please check the config.log for details.]) @@ -195,4 +195,4 @@ dnl Various checks for GD features PHP_SUBST(GDLIB_CFLAGS) PHP_SUBST(GDLIB_LIBS) PHP_SUBST(GD_SHARED_LIBADD) -fi +fi \ No newline at end of file diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index 6695976d0e243..d9e0e5b184d83 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -34,6 +34,7 @@ if (PHP_GD != "no") { CHECK_LIB("Gdi32.lib", "gd", PHP_GD); EXTENSION("gd", "gd.c", null, "-Iext/gd/libgd", "php_gd2.dll"); + ADD_SOURCES("gd_image_object.c"); ADD_SOURCES("ext/gd/libgd", "gd2copypal.c gd.c \ gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \ gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \ diff --git a/ext/gd/gd.c b/ext/gd/gd.c index b621bc23bd107..dc4fc206ff7dc 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -35,7 +35,7 @@ #include "php_gd.h" #include "ext/standard/info.h" #include "php_open_temporary_file.h" - +#include "gd_image_object.h" #ifdef HAVE_SYS_WAIT_H # include @@ -57,7 +57,6 @@ #include "gd_compat.h" -#include "gd_image_object.h" static int le_gd_font; @@ -408,7 +407,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, } } - im = php_gd_image_ptr_from_zval_p(imgind); + im = php_gd_libgdimageptr_from_zval_p(imgind); if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3) { q = quality; /* or colorindex for foreground of BW images (defaults to black) */ @@ -541,12 +540,6 @@ void php_gd_error_method(int type, const char *format, va_list args) } /* }}} */ -static zend_object_handlers gd_ext_image_object_handlers; - -static const zend_function_entry gd_image_methods[] = { - PHP_FE_END -}; - /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(gd) @@ -977,11 +970,11 @@ PHP_FUNCTION(imagesetstyle) int index = 0; uint32_t num_styles; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &styles) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &styles) == FAILURE) { return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles)); if (num_styles == 0) { @@ -1031,7 +1024,7 @@ PHP_FUNCTION(imagecreatetruecolor) RETURN_FALSE; } - php_gd_image_object_from_gd_ptr(return_value, im); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im); } /* }}} */ @@ -1046,7 +1039,7 @@ PHP_FUNCTION(imageistruecolor) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); RETURN_BOOL(im->trueColor); } @@ -1065,7 +1058,7 @@ PHP_FUNCTION(imagetruecolortopalette) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (ncolors <= 0 || ZEND_LONG_INT_OVFL(ncolors)) { zend_value_error("Number of colors has to be greater than zero and no more than %d", INT_MAX); @@ -1092,7 +1085,7 @@ PHP_FUNCTION(imagepalettetotruecolor) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (gdImagePaletteToTrueColor(im) == 0) { RETURN_FALSE; @@ -1114,8 +1107,8 @@ PHP_FUNCTION(imagecolormatch) return; } - im1 = php_gd_image_ptr_from_zval_p(IM1); - im2 = php_gd_image_ptr_from_zval_p(IM2); + im1 = php_gd_libgdimageptr_from_zval_p(IM1); + im2 = php_gd_libgdimageptr_from_zval_p(IM2); result = gdImageColorMatch(im1, im2); switch (result) { @@ -1153,7 +1146,7 @@ PHP_FUNCTION(imagesetthickness) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageSetThickness(im, thick); @@ -1173,10 +1166,9 @@ PHP_FUNCTION(imagefilledellipse) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageFilledEllipse(im, cx, cy, w, h, color); - RETURN_TRUE; } /* }}} */ @@ -1194,7 +1186,7 @@ PHP_FUNCTION(imagefilledarc) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); e = E; if (e < 0) { @@ -1224,7 +1216,7 @@ PHP_FUNCTION(imagealphablending) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageAlphaBlending(im, blend); @@ -1244,7 +1236,7 @@ PHP_FUNCTION(imagesavealpha) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageSaveAlpha(im, save); @@ -1264,7 +1256,7 @@ PHP_FUNCTION(imagelayereffect) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageAlphaBlending(im, effect); @@ -1291,7 +1283,7 @@ PHP_FUNCTION(imagecolorallocatealpha) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1318,7 +1310,7 @@ PHP_FUNCTION(imagecolorresolvealpha) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1341,7 +1333,7 @@ PHP_FUNCTION(imagecolorclosestalpha) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1364,7 +1356,7 @@ PHP_FUNCTION(imagecolorexactalpha) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -1388,8 +1380,8 @@ PHP_FUNCTION(imagecopyresampled) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); - im_dst = php_gd_image_ptr_from_zval_p(DIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); + im_dst = php_gd_libgdimageptr_from_zval_p(DIM); srcX = SX; srcY = SY; @@ -1473,7 +1465,7 @@ PHP_FUNCTION(imagegrabwindow) RETURN_FALSE; } - RETURN_OBJ(gd_ext_image_object_init(return_value, im)); + gd_ext_image_object_init(return_value, im); } /* }}} */ @@ -1530,7 +1522,7 @@ PHP_FUNCTION(imagegrabscreen) RETURN_FALSE; } - php_gd_image_object_from_gd_ptr(return_value, im); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im); } /* }}} */ #endif /* PHP_WIN32 */ @@ -1549,14 +1541,14 @@ PHP_FUNCTION(imagerotate) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); im_dst = gdImageRotateInterpolated(im_src, (const float)degrees, color); if (im_dst == NULL) { RETURN_FALSE; } - php_gd_image_object_from_gd_ptr(return_value, im_dst); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im_dst); } /* }}} */ @@ -1571,8 +1563,8 @@ PHP_FUNCTION(imagesettile) return; } - im = php_gd_image_ptr_from_zval_p(IM); - tile = php_gd_image_ptr_from_zval_p(TILE); + im = php_gd_libgdimageptr_from_zval_p(IM); + tile = php_gd_libgdimageptr_from_zval_p(TILE); gdImageSetTile(im, tile); @@ -1591,8 +1583,8 @@ PHP_FUNCTION(imagesetbrush) return; } - im = php_gd_image_ptr_from_zval_p(IM); - tile = php_gd_image_ptr_from_zval_p(TILE); + im = php_gd_libgdimageptr_from_zval_p(IM); + tile = php_gd_libgdimageptr_from_zval_p(TILE); gdImageSetBrush(im, tile); @@ -1627,7 +1619,7 @@ PHP_FUNCTION(imagecreate) RETURN_FALSE; } - php_gd_image_object_from_gd_ptr(return_value, im); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im); } /* }}} */ @@ -1827,7 +1819,7 @@ PHP_FUNCTION(imagecreatefromstring) RETURN_FALSE; } - php_gd_image_object_from_gd_ptr(return_value, im); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im); } /* }}} */ @@ -1945,7 +1937,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, /* register_im: */ if (im) { php_stream_close(stream); - php_gd_image_object_from_gd_ptr(return_value, im); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im); return; } @@ -2085,7 +2077,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char return; } - im = php_gd_image_ptr_from_zval_p(imgind); + im = php_gd_libgdimageptr_from_zval_p(imgind); if (argc > 1) { fn = file; @@ -2289,7 +2281,7 @@ PHP_FUNCTION(imagecolorallocate) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2314,8 +2306,8 @@ PHP_FUNCTION(imagepalettecopy) return; } - src = php_gd_image_ptr_from_zval_p(srcim); - dst = php_gd_image_ptr_from_zval_p(dstim); + src = php_gd_libgdimageptr_from_zval_p(srcim); + dst = php_gd_libgdimageptr_from_zval_p(dstim); gdImagePaletteCopy(dst, src); } @@ -2335,7 +2327,7 @@ PHP_FUNCTION(imagecolorat) Z_PARAM_LONG(y) ZEND_PARSE_PARAMETERS_END(); - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (gdImageTrueColor(im)) { if (im->tpixels && gdImageBoundsSafe(im, x, y)) { @@ -2367,7 +2359,7 @@ PHP_FUNCTION(imagecolorclosest) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2389,7 +2381,7 @@ PHP_FUNCTION(imagecolorclosesthwb) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2412,7 +2404,7 @@ PHP_FUNCTION(imagecolordeallocate) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); /* We can return right away for a truecolor image as deallocating colours is meaningless here */ if (gdImageTrueColor(im)) { @@ -2443,7 +2435,7 @@ PHP_FUNCTION(imagecolorresolve) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2465,7 +2457,7 @@ PHP_FUNCTION(imagecolorexact) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2488,7 +2480,7 @@ PHP_FUNCTION(imagecolorset) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); CHECK_RGBA_RANGE(red, Red); CHECK_RGBA_RANGE(green, Green); @@ -2521,7 +2513,7 @@ PHP_FUNCTION(imagecolorsforindex) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); col = index; @@ -2559,7 +2551,7 @@ PHP_FUNCTION(imagegammacorrect) gamma = input / output; - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (gdImageTrueColor(im)) { int x, y, c; @@ -2605,7 +2597,7 @@ PHP_FUNCTION(imagesetpixel) Z_PARAM_LONG(col) ZEND_PARSE_PARAMETERS_END(); - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageSetPixel(im, x, y, col); RETURN_TRUE; @@ -2624,7 +2616,7 @@ PHP_FUNCTION(imageline) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (im->AA) { gdImageSetAntiAliased(im, col); @@ -2647,7 +2639,7 @@ PHP_FUNCTION(imagedashedline) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageDashedLine(im, x1, y1, x2, y2, col); RETURN_TRUE; @@ -2666,7 +2658,7 @@ PHP_FUNCTION(imagerectangle) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageRectangle(im, x1, y1, x2, y2, col); RETURN_TRUE; @@ -2685,7 +2677,7 @@ PHP_FUNCTION(imagefilledrectangle) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageFilledRectangle(im, x1, y1, x2, y2, col); RETURN_TRUE; } @@ -2704,7 +2696,7 @@ PHP_FUNCTION(imagearc) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); e = E; if (e < 0) { @@ -2733,7 +2725,7 @@ PHP_FUNCTION(imageellipse) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageEllipse(im, cx, cy, w, h, color); RETURN_TRUE; @@ -2752,7 +2744,7 @@ PHP_FUNCTION(imagefilltoborder) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageFillToBorder(im, x, y, border, col); RETURN_TRUE; @@ -2771,7 +2763,7 @@ PHP_FUNCTION(imagefill) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); gdImageFill(im, x, y, col); RETURN_TRUE; @@ -2789,7 +2781,7 @@ PHP_FUNCTION(imagecolorstotal) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); RETURN_LONG(gdImageColorsTotal(im)); } @@ -2808,7 +2800,7 @@ PHP_FUNCTION(imagecolortransparent) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (argc > 1) { gdImageColorTransparent(im, COL); @@ -2831,7 +2823,7 @@ PHP_FUNCTION(imageinterlace) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (argc > 1) { gdImageInterlace(im, INT); @@ -2859,7 +2851,7 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); npoints = NPOINTS; col = COL; @@ -3058,7 +3050,7 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); col = COL; @@ -3149,8 +3141,8 @@ PHP_FUNCTION(imagecopy) return; } - im_dst = php_gd_image_ptr_from_zval_p(DIM); - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_dst = php_gd_libgdimageptr_from_zval_p(DIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); srcX = SX; srcY = SY; @@ -3177,8 +3169,8 @@ PHP_FUNCTION(imagecopymerge) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); - im_dst = php_gd_image_ptr_from_zval_p(DIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); + im_dst = php_gd_libgdimageptr_from_zval_p(DIM); srcX = SX; srcY = SY; @@ -3206,8 +3198,8 @@ PHP_FUNCTION(imagecopymergegray) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); - im_dst = php_gd_image_ptr_from_zval_p(DIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); + im_dst = php_gd_libgdimageptr_from_zval_p(DIM); srcX = SX; srcY = SY; @@ -3235,8 +3227,8 @@ PHP_FUNCTION(imagecopyresized) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); - im_dst = php_gd_image_ptr_from_zval_p(DIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); + im_dst = php_gd_libgdimageptr_from_zval_p(DIM); srcX = SX; srcY = SY; @@ -3268,7 +3260,7 @@ PHP_FUNCTION(imagesx) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); RETURN_LONG(gdImageSX(im)); } @@ -3285,7 +3277,7 @@ PHP_FUNCTION(imagesy) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); RETURN_LONG(gdImageSY(im)); } @@ -3303,7 +3295,7 @@ PHP_FUNCTION(imagesetclip) return; } - im = php_gd_image_ptr_from_zval_p(im_zval); + im = php_gd_libgdimageptr_from_zval_p(im_zval); gdImageSetClip(im, x1, y1, x2, y2); RETURN_TRUE; @@ -3322,7 +3314,7 @@ PHP_FUNCTION(imagegetclip) return; } - im = php_gd_image_ptr_from_zval_p(im_zval); + im = php_gd_libgdimageptr_from_zval_p(im_zval); gdImageGetClip(im, &x1, &y1, &x2, &y2); @@ -3397,7 +3389,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int } else if (zend_parse_parameters(argc, "Oddlllss|a", &IM, gd_image_ce, &ptsize, &angle, &x, &y, &col, &fontname, &fontname_len, &str, &str_len, &EXT) == FAILURE) { return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); } /* convert angle to radians */ @@ -3459,7 +3451,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int if (zend_parse_parameters(1, "O", &SIM, gd_image_ce) == FAILURE) { \ return; \ } \ - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS) { @@ -3493,7 +3485,7 @@ static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); if (gdImageBrightness(im_src, (int)brightness) == 1) { RETURN_TRUE; @@ -3512,7 +3504,7 @@ static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); if (gdImageContrast(im_src, (int)contrast) == 1) { RETURN_TRUE; @@ -3532,7 +3524,7 @@ static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) { RETURN_TRUE; @@ -3607,7 +3599,7 @@ static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); if (gdImageSmooth(im_src, (float)weight)==1) { RETURN_TRUE; @@ -3627,7 +3619,7 @@ static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (gdImagePixelate(im, (int) blocksize, (const unsigned int) mode)) { RETURN_TRUE; @@ -3648,7 +3640,7 @@ static void php_image_filter_scatter(INTERNAL_FUNCTION_PARAMETERS) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (hash_colors) { uint32_t i = 0; @@ -3726,7 +3718,7 @@ PHP_FUNCTION(imageconvolution) return; } - im_src = php_gd_image_ptr_from_zval_p(SIM); + im_src = php_gd_libgdimageptr_from_zval_p(SIM); nelem = zend_hash_num_elements(Z_ARRVAL_P(hash_matrix)); if (nelem != 3) { @@ -3774,7 +3766,7 @@ PHP_FUNCTION(imageflip) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); switch (mode) { case GD_FLIP_VERTICAL: @@ -3810,7 +3802,7 @@ PHP_FUNCTION(imageantialias) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (im->trueColor) { im->AA = alias; } @@ -3834,7 +3826,7 @@ PHP_FUNCTION(imagecrop) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) { rect.x = zval_get_long(tmp); @@ -3870,8 +3862,7 @@ PHP_FUNCTION(imagecrop) RETURN_FALSE; } - - RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop)); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im_crop); } /* }}} */ @@ -3890,7 +3881,7 @@ PHP_FUNCTION(imagecropauto) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); switch (mode) { case GD_CROP_DEFAULT: @@ -3918,7 +3909,7 @@ PHP_FUNCTION(imagecropauto) RETURN_FALSE; } - RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop)); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im_crop); } /* }}} */ @@ -3938,7 +3929,7 @@ PHP_FUNCTION(imagescale) } method = tmp_m; - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (tmp_h < 0 || tmp_w < 0) { /* preserve ratio */ @@ -3973,7 +3964,7 @@ PHP_FUNCTION(imagescale) RETURN_FALSE; } - RETURN_OBJ(gd_ext_image_object_init(return_value, im_scaled)); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im_scaled); } /* }}} */ @@ -3997,7 +3988,7 @@ PHP_FUNCTION(imageaffine) return; } - src = php_gd_image_ptr_from_zval_p(IM); + src = php_gd_libgdimageptr_from_zval_p(IM); if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) { zend_value_error("Affine array must have six elements"); @@ -4068,7 +4059,7 @@ PHP_FUNCTION(imageaffine) RETURN_FALSE; } - RETURN_OBJ(gd_ext_image_object_init(return_value, dst)); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, dst); } /* }}} */ @@ -4234,7 +4225,7 @@ PHP_FUNCTION(imagesetinterpolation) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); if (method == -1) { method = GD_BILINEAR_FIXED; @@ -4255,7 +4246,7 @@ PHP_FUNCTION(imageresolution) return; } - im = php_gd_image_ptr_from_zval_p(IM); + im = php_gd_libgdimageptr_from_zval_p(IM); switch (ZEND_NUM_ARGS()) { case 3: diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c index 1978767b8ef12..c5d917aa2d98e 100644 --- a/ext/gd/gd_image_object.c +++ b/ext/gd/gd_image_object.c @@ -17,6 +17,7 @@ */ #include "gd_image_object.h" +#include "zend.h" static zend_object_handlers php_gd_image_object_handlers; @@ -24,13 +25,15 @@ static const zend_function_entry gd_image_object_methods[] = { PHP_FE_END }; -static zend_always_inline php_gd_image_object* php_gd_image_object_from_ptr(zend_object* obj) { - return (php_gd_image_object *)((char *)(obj) - XtOffsetOf(php_gd_image_object, std)); +static zend_function *php_gd_image_object_get_constructor(zend_object *object) { + zend_throw_error(NULL, "You cannot initialize a GdImage object except through helper functions"); + return NULL; } -static zend_object* php_gd_image_object_create(zend_class_entry * class_type) { - php_gd_image_object* intern = emalloc(sizeof(php_gd_image_object) + zend_object_properties_size(class_type)); - memset(intern, 0, sizeof(php_gd_image_object)); +zend_object *php_gd_image_object_create(zend_class_entry *class_type) { + size_t block_len = sizeof(php_gd_image_object) + zend_object_properties_size(class_type); + php_gd_image_object *intern = emalloc(block_len); + memset(intern, 0, block_len); zend_object_std_init(&intern->std, class_type); object_properties_init(&intern->std, class_type); @@ -39,25 +42,20 @@ static zend_object* php_gd_image_object_create(zend_class_entry * class_type) { return &intern->std; }; -static void php_gd_image_object_free(zend_object* intern) { - php_gd_image_object* img_obj_ptr = php_gd_image_object_from_ptr(intern); +static void php_gd_image_object_free(zend_object *intern) { + php_gd_image_object *img_obj_ptr = php_gd_exgdimage_from_zobj_p(intern); gdImageDestroy(img_obj_ptr->image); img_obj_ptr->image = NULL; + zend_object_std_dtor(intern); }; -static void php_gd_image_object_from_gd_ptr(zval* val, gdImagePtr image) { +void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) { object_init_ex(val, gd_image_ce); - php_gd_image_object_from_ptr(Z_OBJ_P(val))->image = image; - return Z_OBJ_P(val); -} - -static zend_function *php_gd_image_object_get_constructor(zend_object *object) { - zend_throw_error(NULL, "Directly constructing a GdImage object is prohibited"); - return NULL; + php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; } -static void php_gd_object_minit_helper() { +void php_gd_object_minit_helper() { zend_class_entry ce; INIT_CLASS_ENTRY(ce, "GdImage", gd_image_object_methods); gd_image_ce = zend_register_internal_class(&ce); @@ -68,6 +66,10 @@ static void php_gd_object_minit_helper() { memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); php_gd_image_object_handlers.clone_obj = NULL; php_gd_image_object_handlers.free_obj = php_gd_image_object_free; - php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; + php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; php_gd_image_object_handlers.offset = XtOffsetOf(php_gd_image_object, std); +} + +PHP_METHOD(GdImage, Create) { + } \ No newline at end of file diff --git a/ext/gd/gd_image_object.h b/ext/gd/gd_image_object.h index 7409a17119368..02a635001a878 100644 --- a/ext/gd/gd_image_object.h +++ b/ext/gd/gd_image_object.h @@ -29,8 +29,16 @@ typedef struct _gd_ext_image_object { zend_object std; } php_gd_image_object; -static void php_gd_object_minit_helper(); -static zend_always_inline gdImagePtr php_gd_image_ptr_from_zval_p(zval*); -static void php_gd_image_object_from_gd_ptr(zval* val, gdImagePtr image); +void php_gd_object_minit_helper(); + +static zend_always_inline php_gd_image_object* php_gd_exgdimage_from_zobj_p(zend_object* obj) { + return (php_gd_image_object *) ((char *) (obj) - XtOffsetOf(php_gd_image_object, std)); +} + +static zend_always_inline gdImagePtr php_gd_libgdimageptr_from_zval_p(zval* zp) { + return php_gd_exgdimage_from_zobj_p(Z_OBJ_P(zp))->image; +} + +void php_gd_assign_libgdimageptr_as_extgdimage(zval* val, gdImagePtr image); #endif //SRC_GD_IMAGE_OBJECT_H From 60784e2f22750a1282d9134baac9145de1c264e8 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 24 Sep 2019 22:18:25 +0100 Subject: [PATCH 03/11] W32 build --- ext/gd/config.w32 | 3 +-- ext/gd/gd_image_object.c | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index d9e0e5b184d83..6f894caf5ef81 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -33,8 +33,7 @@ if (PHP_GD != "no") { CHECK_LIB("User32.lib", "gd", PHP_GD); CHECK_LIB("Gdi32.lib", "gd", PHP_GD); - EXTENSION("gd", "gd.c", null, "-Iext/gd/libgd", "php_gd2.dll"); - ADD_SOURCES("gd_image_object.c"); + EXTENSION("gd", "gd.c gd_image_object.x", null, "-Iext/gd/libgd", "php_gd2.dll"); ADD_SOURCES("ext/gd/libgd", "gd2copypal.c gd.c \ gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \ gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \ diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c index c5d917aa2d98e..bd7c6df982aa0 100644 --- a/ext/gd/gd_image_object.c +++ b/ext/gd/gd_image_object.c @@ -69,7 +69,3 @@ void php_gd_object_minit_helper() { php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; php_gd_image_object_handlers.offset = XtOffsetOf(php_gd_image_object, std); } - -PHP_METHOD(GdImage, Create) { - -} \ No newline at end of file From 362b291289174bc4785f09985f152cfcdc61ed12 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 24 Sep 2019 22:18:43 +0100 Subject: [PATCH 04/11] W32 build --- ext/gd/config.w32 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index 6f894caf5ef81..5907af1136dd9 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -33,7 +33,7 @@ if (PHP_GD != "no") { CHECK_LIB("User32.lib", "gd", PHP_GD); CHECK_LIB("Gdi32.lib", "gd", PHP_GD); - EXTENSION("gd", "gd.c gd_image_object.x", null, "-Iext/gd/libgd", "php_gd2.dll"); + EXTENSION("gd", "gd.c gd_image_object.c", null, "-Iext/gd/libgd", "php_gd2.dll"); ADD_SOURCES("ext/gd/libgd", "gd2copypal.c gd.c \ gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \ gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \ From 921e088e88ed83c41aa8fe20eb2f16865633541c Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 24 Sep 2019 22:52:41 +0100 Subject: [PATCH 05/11] Fixed bad symbol inside W32 ifdef --- ext/gd/gd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index dc4fc206ff7dc..9ac49945d7017 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1465,7 +1465,7 @@ PHP_FUNCTION(imagegrabwindow) RETURN_FALSE; } - gd_ext_image_object_init(return_value, im); + php_gd_assign_libgdimageptr_as_extgdimage(return_value, im); } /* }}} */ From 7c97e0b1891786624e0db475ffae15dbd7927822 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 25 Sep 2019 01:41:37 +0100 Subject: [PATCH 06/11] Serialization protection --- ext/gd/gd.c | 2 +- ext/gd/gd_image_object.c | 12 ++++++++++- .../tests/gdimage_prevent_serialization.phpt | 21 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 ext/gd/tests/gdimage_prevent_serialization.phpt diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 9ac49945d7017..42a65ad204bc9 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3782,7 +3782,7 @@ PHP_FUNCTION(imageflip) break; default: - php_error_docref(NULL, E_WARNING, "Unknown flip mode"); + zend_value_error("Unknown flip mode"); RETURN_FALSE; } diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c index bd7c6df982aa0..bfa5b382f1cd7 100644 --- a/ext/gd/gd_image_object.c +++ b/ext/gd/gd_image_object.c @@ -17,12 +17,20 @@ */ #include "gd_image_object.h" +#include "gd_arginfo.h" #include "zend.h" +#include "zend_interfaces.h" +#include "../../Zend/zend.h" + +/* + * List of unique methods implemented by GdImage + */ static zend_object_handlers php_gd_image_object_handlers; +static PHP_METHOD(GdImage, __wakeup); static const zend_function_entry gd_image_object_methods[] = { - PHP_FE_END + PHP_FE_END }; static zend_function *php_gd_image_object_get_constructor(zend_object *object) { @@ -61,6 +69,8 @@ void php_gd_object_minit_helper() { gd_image_ce = zend_register_internal_class(&ce); gd_image_ce->ce_flags |= ZEND_ACC_FINAL; gd_image_ce->create_object = php_gd_image_object_create; + gd_image_ce->serialize = zend_class_serialize_deny; + gd_image_ce->unserialize = zend_class_unserialize_deny; /* setting up the object handlers for the GdImage class */ memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); diff --git a/ext/gd/tests/gdimage_prevent_serialization.phpt b/ext/gd/tests/gdimage_prevent_serialization.phpt new file mode 100644 index 0000000000000..ef08444d37d75 --- /dev/null +++ b/ext/gd/tests/gdimage_prevent_serialization.phpt @@ -0,0 +1,21 @@ +--TEST-- +GdImage instances must not be serialized +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught Exception: Serialization of 'GdImage' is not allowed in %s:%d +Stack trace: +#0 %s(%d): serialize(Object(GdImage)) +#1 {main} + thrown in %s on line %d From cce31cda2c2d5bac5628a25bbb6e943ed891d4f4 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 25 Sep 2019 01:49:49 +0100 Subject: [PATCH 07/11] Remove unnecessary symbol --- ext/gd/gd_image_object.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c index bfa5b382f1cd7..2358e1589806e 100644 --- a/ext/gd/gd_image_object.c +++ b/ext/gd/gd_image_object.c @@ -27,7 +27,6 @@ */ static zend_object_handlers php_gd_image_object_handlers; -static PHP_METHOD(GdImage, __wakeup); static const zend_function_entry gd_image_object_methods[] = { PHP_FE_END From a6fb300bcbebf767f340e628b9436c5341c35379 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 25 Sep 2019 02:00:31 +0100 Subject: [PATCH 08/11] Cleanup unrelated spacing -> tab --- ext/gd/gd.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 42a65ad204bc9..d30ab970f5d91 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -179,7 +179,7 @@ static const zend_function_entry gd_functions[] = { PHP_FE(imagegrabscreen, arginfo_imagegrabscreen) #endif - PHP_FE(imagerotate, arginfo_imagerotate) + PHP_FE(imagerotate, arginfo_imagerotate) PHP_FE(imageflip, arginfo_imageflip) PHP_FE(imageantialias, arginfo_imageantialias) @@ -189,7 +189,7 @@ static const zend_function_entry gd_functions[] = { PHP_FE(imageaffine, arginfo_imageaffine) PHP_FE(imageaffinematrixconcat, arginfo_imageaffinematrixconcat) PHP_FE(imageaffinematrixget, arginfo_imageaffinematrixget) - PHP_FE(imagesetinterpolation, arginfo_imagesetinterpolation) + PHP_FE(imagesetinterpolation, arginfo_imagesetinterpolation) PHP_FE(imagesettile, arginfo_imagesettile) PHP_FE(imagesetbrush, arginfo_imagesetbrush) PHP_FE(imagesetstyle, arginfo_imagesetstyle) @@ -228,7 +228,7 @@ static const zend_function_entry gd_functions[] = { #ifdef HAVE_GD_JPG PHP_FE(imagejpeg, arginfo_imagejpeg) #endif - PHP_FE(imagewbmp, arginfo_imagewbmp) + PHP_FE(imagewbmp, arginfo_imagewbmp) PHP_FE(imagegd, arginfo_imagegd) PHP_FE(imagegd2, arginfo_imagegd2) #ifdef HAVE_GD_BMP @@ -268,12 +268,12 @@ static const zend_function_entry gd_functions[] = { PHP_FE(imagetypes, arginfo_imagetypes) PHP_FE(imagelayereffect, arginfo_imagelayereffect) - PHP_FE(imagexbm, arginfo_imagexbm) + PHP_FE(imagexbm, arginfo_imagexbm) PHP_FE(imagecolormatch, arginfo_imagecolormatch) /* gd filters */ - PHP_FE(imagefilter, arginfo_imagefilter) + PHP_FE(imagefilter, arginfo_imagefilter) PHP_FE(imageconvolution, arginfo_imageconvolution) PHP_FE(imageresolution, arginfo_imageresolution) @@ -578,7 +578,7 @@ PHP_MINIT_FUNCTION(gd) REGISTER_LONG_CONSTANT("IMG_ARC_NOFILL", gdNoFill, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_ARC_EDGED", gdEdged, CONST_CS | CONST_PERSISTENT); - /* GD2 image format types */ + /* GD2 image format types */ REGISTER_LONG_CONSTANT("IMG_GD2_RAW", GD2_FMT_RAW, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_GD2_COMPRESSED", GD2_FMT_COMPRESSED, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_FLIP_HORIZONTAL", GD_FLIP_HORINZONTAL, CONST_CS | CONST_PERSISTENT); @@ -968,19 +968,19 @@ PHP_FUNCTION(imagesetstyle) gdImagePtr im; int *stylearr; int index = 0; - uint32_t num_styles; + uint32_t num_styles; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &styles) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &styles) == FAILURE) { return; } im = php_gd_libgdimageptr_from_zval_p(IM); - num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles)); - if (num_styles == 0) { - zend_value_error("Styles array must not be empty"); - return; - } + num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles)); + if (num_styles == 0) { + zend_value_error("Styles array must not be empty"); + return; + } /* copy the style values in the stylearr */ stylearr = safe_emalloc(sizeof(int), num_styles, 0); From 69a33d620283b34b3d00230e6c15107e682a4609 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 25 Sep 2019 19:37:01 +0100 Subject: [PATCH 09/11] Re-deleted ctx, new copyright --- ext/gd/gd_ctx.c | 215 --------------------------------------- ext/gd/gd_image_object.c | 2 - ext/gd/gd_image_object.h | 2 - 3 files changed, 219 deletions(-) delete mode 100644 ext/gd/gd_ctx.c diff --git a/ext/gd/gd_ctx.c b/ext/gd/gd_ctx.c deleted file mode 100644 index 9bed0d034f462..0000000000000 --- a/ext/gd/gd_ctx.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Stanislav Malyshev | - +----------------------------------------------------------------------+ - */ - -#include "php_gd.h" - -#define CTX_PUTC(c,ctx) ctx->putC(ctx, c) - -static void _php_image_output_putc(struct gdIOCtx *ctx, int c) /* {{{ */ -{ - /* without the following downcast, the write will fail - * (i.e., will write a zero byte) for all - * big endian architectures: - */ - unsigned char ch = (unsigned char) c; - php_write(&ch, 1); -} /* }}} */ - -static int _php_image_output_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ -{ - return php_write((void *)buf, l); -} /* }}} */ - -static void _php_image_output_ctxfree(struct gdIOCtx *ctx) /* {{{ */ -{ - if(ctx) { - efree(ctx); - } -} /* }}} */ - -static void _php_image_stream_putc(struct gdIOCtx *ctx, int c) /* {{{ */ { - char ch = (char) c; - php_stream * stream = (php_stream *)ctx->data; - php_stream_write(stream, &ch, 1); -} /* }}} */ - -static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ -{ - php_stream * stream = (php_stream *)ctx->data; - return php_stream_write(stream, (void *)buf, l); -} /* }}} */ - -static void _php_image_stream_ctxfree(struct gdIOCtx *ctx) /* {{{ */ -{ - if(ctx->data) { - ctx->data = NULL; - } - if(ctx) { - efree(ctx); - } -} /* }}} */ - -static void _php_image_stream_ctxfreeandclose(struct gdIOCtx *ctx) /* {{{ */ -{ - - if(ctx->data) { - php_stream_close((php_stream *) ctx->data); - ctx->data = NULL; - } - if(ctx) { - efree(ctx); - } -} /* }}} */ - -/* {{{ _php_image_output_ctx */ -static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) -{ - zval *imgind; - char *file = NULL; - size_t file_len = 0; - zend_long quality, basefilter; - zend_bool compressed = 1; - gdImagePtr im; - int argc = ZEND_NUM_ARGS(); - int q = -1, i; - int f = -1; - gdIOCtx *ctx = NULL; - zval *to_zval = NULL; - php_stream *stream; - int close_stream = 1; - - /* The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called - * from imagey(). - */ - switch (image_type) { - case PHP_GDIMG_TYPE_XBM: - if (zend_parse_parameters(argc, "rp!|ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) { - return; - } - break; - case PHP_GDIMG_TYPE_BMP: - if (zend_parse_parameters(argc, "r|z!b", &imgind, &to_zval, &compressed) == FAILURE) { - return; - } - break; - default: - /* PHP_GDIMG_TYPE_GIF - * PHP_GDIMG_TYPE_PNG - * PHP_GDIMG_TYPE_JPG - * PHP_GDIMG_TYPE_WBM - * PHP_GDIMG_TYPE_WEBP - * */ - if (zend_parse_parameters(argc, "r|z!ll", &imgind, &to_zval, &quality, &basefilter) == FAILURE) { - return; - } - } - - if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(imgind), "Image", phpi_get_le_gd())) == NULL) { - return; - } - - if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3) { - q = quality; /* or colorindex for foreground of BW images (defaults to black) */ - if (argc == 4) { - f = basefilter; - } - } - - if (argc > 1 && to_zval != NULL) { - if (Z_TYPE_P(to_zval) == IS_RESOURCE) { - php_stream_from_zval_no_verify(stream, to_zval); - if (stream == NULL) { - RETURN_FALSE; - } - close_stream = 0; - } else if (Z_TYPE_P(to_zval) == IS_STRING) { - if (CHECK_ZVAL_NULL_PATH(to_zval)) { - zend_type_error("Invalid 2nd parameter, filename must not contain null bytes"); - return; - } - - stream = php_stream_open_wrapper(Z_STRVAL_P(to_zval), "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); - if (stream == NULL) { - RETURN_FALSE; - } - } else { - php_error_docref(NULL, E_WARNING, "Invalid 2nd parameter, it must a filename or a stream"); - RETURN_FALSE; - } - } else if (argc > 1 && file != NULL) { - stream = php_stream_open_wrapper(file, "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); - if (stream == NULL) { - RETURN_FALSE; - } - } else { - ctx = ecalloc(1, sizeof(gdIOCtx)); - ctx->putC = _php_image_output_putc; - ctx->putBuf = _php_image_output_putbuf; - ctx->gd_free = _php_image_output_ctxfree; - } - - if (!ctx) { - ctx = ecalloc(1, sizeof(gdIOCtx)); - ctx->putC = _php_image_stream_putc; - ctx->putBuf = _php_image_stream_putbuf; - if (close_stream) { - ctx->gd_free = _php_image_stream_ctxfreeandclose; - } else { - ctx->gd_free = _php_image_stream_ctxfree; - } - ctx->data = (void *)stream; - } - - switch(image_type) { - case PHP_GDIMG_TYPE_JPG: - (*func_p)(im, ctx, q); - break; - case PHP_GDIMG_TYPE_WEBP: - if (q == -1) { - q = 80; - } - (*func_p)(im, ctx, q); - break; - case PHP_GDIMG_TYPE_PNG: - (*func_p)(im, ctx, q, f); - break; - case PHP_GDIMG_TYPE_XBM: - case PHP_GDIMG_TYPE_WBM: - if (argc < 3) { - for(i=0; i < gdImageColorsTotal(im); i++) { - if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; - } - q = i; - } - if (image_type == PHP_GDIMG_TYPE_XBM) { - (*func_p)(im, file ? file : "", q, ctx); - } else { - (*func_p)(im, q, ctx); - } - break; - case PHP_GDIMG_TYPE_BMP: - (*func_p)(im, ctx, (int) compressed); - break; - default: - (*func_p)(im, ctx); - break; - } - - ctx->gd_free(ctx); - - RETURN_TRUE; -} -/* }}} */ diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c index 2358e1589806e..3073b9e365da0 100644 --- a/ext/gd/gd_image_object.c +++ b/ext/gd/gd_image_object.c @@ -1,6 +1,4 @@ /* - +----------------------------------------------------------------------+ - | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ diff --git a/ext/gd/gd_image_object.h b/ext/gd/gd_image_object.h index 02a635001a878..847c06ecb85a5 100644 --- a/ext/gd/gd_image_object.h +++ b/ext/gd/gd_image_object.h @@ -1,6 +1,4 @@ /* - +----------------------------------------------------------------------+ - | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ From 1fb3c51a50d4c76a1c61bc9000511d875d42e18f Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 26 Sep 2019 11:32:43 +0100 Subject: [PATCH 10/11] Whitespace, bracket style, resource dec fixes in stubs --- ext/gd/gd.c | 8 +++---- ext/gd/gd.stub.php | 46 ++++++++++++++++++++-------------------- ext/gd/gd_arginfo.h | 9 +------- ext/gd/gd_image_object.c | 15 ++++++++----- ext/gd/gd_image_object.h | 6 ++++-- 5 files changed, 42 insertions(+), 42 deletions(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index b744fe2ff0306..aed3a1ff0c86e 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -966,18 +966,18 @@ PHP_FUNCTION(imagesetstyle) gdImagePtr im; int *stylearr; int index = 0; - uint32_t num_styles; + uint32_t num_styles; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &styles) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oa", &IM, gd_image_ce, &styles) == FAILURE) { return; } im = php_gd_libgdimageptr_from_zval_p(IM); num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles)); - if (num_styles == 0) { + if (num_styles == 0){ zend_value_error("Styles array must not be empty"); - return; + return; } /* copy the style values in the stylearr */ diff --git a/ext/gd/gd.stub.php b/ext/gd/gd.stub.php index addffb1433920..7b639f9371037 100644 --- a/ext/gd/gd.stub.php +++ b/ext/gd/gd.stub.php @@ -7,7 +7,7 @@ function imageloadfont(string $filename) {} function imagesetstyle($im, array $styles): bool {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatetruecolor(int $x_size, int $y_size) {} function imageistruecolor(GdImage $im): bool {} @@ -46,74 +46,74 @@ function imagecopyresampled(GdImage $dst_im, GdImage $src_im, int $dst_x, int $d #ifdef PHP_WIN32 -/** @return resource|false */ +/** @return GdImage|false */ function imagegrabwindow(int $handle, int $client_area = 0) {} -/** @return resource|false */ +/** @return GdImage|false */ function imagegrabscreen() {} #endif -/** @return resource|false */ +/** @return GdImage|false */ function imagerotate(GdImage $im, float $angle, int $bgdcolor, int $ignoretransparent = 0) {} function imagesettile(GdImage $im, $tile): bool {} function imagesetbrush(GdImage $im, $brush): bool {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecreate(int $x_size, int $y_size) {} function imagetypes(): int {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromstring(string $image) {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromgif(string $filename) {} #ifdef HAVE_GD_JPG -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromjpeg(string $filename) {} #endif #ifdef HAVE_GD_PNG -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefrompng(string $filename) {} #endif #ifdef HAVE_GD_WEBP -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromwebp(string $filename) {} #endif -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromxbm(string $filename) {} #ifdef HAVE_GD_XPM -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromxpm(string $filename) {} #endif -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromwbmp(string $filename) {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromgd(string $filename) {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromgd2(string $filename) {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromgd2part(string $filename, int $srcX, int $srcY, int $width, int $height) {} #ifdef HAVE_GD_BMP -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefrombmp(string $filename) {} #endif #ifdef HAVE_GD_TGA -/** @return resource|false */ +/** @return GdImage|false */ function imagecreatefromtga(string $filename) {} #endif @@ -215,7 +215,7 @@ function imagecharup(GdImage $im, int $font, int $x, int $y, string $c, int $col function imagestring(GdImage $im, int $font, int $x, int $y, string $str, int $col): bool {} -function imagestringup($im, int $font, int $x, int $y, string $str, int $col): bool {} +function imagestringup(GdImage $im, int $font, int $x, int $y, string $str, int $col): bool {} function imagecopy(GdImage $dst_im, GdImage $src_im, int $dst_x, int $dst_y, int $src_x, int $src_y, int $src_w, int $src_h): bool {} @@ -252,16 +252,16 @@ function imageflip(GdImage $im, int $mode): bool {} function imageantialias(GdImage $im, bool $on): bool {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecrop(GdImage $im, array $rect) {} -/** @return resource|false */ +/** @return GdImage|false */ function imagecropauto(GdImage $im, int $mode = IMG_CROP_DEFAULT, float $threshold = 0.5, int $color = -1) {} -/** @return resource|false */ +/** @return GdImage|false */ function imagescale(GdImage $im, int $new_width, int $new_height = UNKNOWN, int $mode = IMG_BILINEAR_FIXED) {} -/** @return resource|false */ +/** @return GdImage|false */ function imageaffine(GdImage $im, array $affine, array $clip = UNKNOWN) {} /** @return array|false */ diff --git a/ext/gd/gd_arginfo.h b/ext/gd/gd_arginfo.h index 40639b46c6152..1f036c8ea96b5 100644 --- a/ext/gd/gd_arginfo.h +++ b/ext/gd/gd_arginfo.h @@ -402,14 +402,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagestring, 0, 6, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagestringup, 0, 6, _IS_BOOL, 0) - ZEND_ARG_INFO(0, im) - ZEND_ARG_TYPE_INFO(0, font, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, x, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, y, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, col, IS_LONG, 0) -ZEND_END_ARG_INFO() +#define arginfo_imagestringup arginfo_imagestring ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagecopy, 0, 8, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, dst_im, GdImage, 0) diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c index 3073b9e365da0..c23fc44037454 100644 --- a/ext/gd/gd_image_object.c +++ b/ext/gd/gd_image_object.c @@ -30,12 +30,14 @@ static const zend_function_entry gd_image_object_methods[] = { PHP_FE_END }; -static zend_function *php_gd_image_object_get_constructor(zend_object *object) { +static zend_function *php_gd_image_object_get_constructor(zend_object *object) +{ zend_throw_error(NULL, "You cannot initialize a GdImage object except through helper functions"); return NULL; } -zend_object *php_gd_image_object_create(zend_class_entry *class_type) { +zend_object *php_gd_image_object_create(zend_class_entry *class_type) +{ size_t block_len = sizeof(php_gd_image_object) + zend_object_properties_size(class_type); php_gd_image_object *intern = emalloc(block_len); memset(intern, 0, block_len); @@ -47,7 +49,8 @@ zend_object *php_gd_image_object_create(zend_class_entry *class_type) { return &intern->std; }; -static void php_gd_image_object_free(zend_object *intern) { +static void php_gd_image_object_free(zend_object *intern) +{ php_gd_image_object *img_obj_ptr = php_gd_exgdimage_from_zobj_p(intern); gdImageDestroy(img_obj_ptr->image); img_obj_ptr->image = NULL; @@ -55,12 +58,14 @@ static void php_gd_image_object_free(zend_object *intern) { zend_object_std_dtor(intern); }; -void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) { +void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) +{ object_init_ex(val, gd_image_ce); php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; } -void php_gd_object_minit_helper() { +void php_gd_object_minit_helper() +{ zend_class_entry ce; INIT_CLASS_ENTRY(ce, "GdImage", gd_image_object_methods); gd_image_ce = zend_register_internal_class(&ce); diff --git a/ext/gd/gd_image_object.h b/ext/gd/gd_image_object.h index 847c06ecb85a5..091a04e6d8c18 100644 --- a/ext/gd/gd_image_object.h +++ b/ext/gd/gd_image_object.h @@ -29,11 +29,13 @@ typedef struct _gd_ext_image_object { void php_gd_object_minit_helper(); -static zend_always_inline php_gd_image_object* php_gd_exgdimage_from_zobj_p(zend_object* obj) { +static zend_always_inline php_gd_image_object* php_gd_exgdimage_from_zobj_p(zend_object* obj) +{ return (php_gd_image_object *) ((char *) (obj) - XtOffsetOf(php_gd_image_object, std)); } -static zend_always_inline gdImagePtr php_gd_libgdimageptr_from_zval_p(zval* zp) { +static zend_always_inline gdImagePtr php_gd_libgdimageptr_from_zval_p(zval* zp) +{ return php_gd_exgdimage_from_zobj_p(Z_OBJ_P(zp))->image; } From 9d0b12e58b77875bac07b0760327c2ff3f1a74e1 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 27 Sep 2019 18:47:24 +0100 Subject: [PATCH 11/11] Moved everything into gd.c --- ext/gd/config.m4 | 4 +- ext/gd/config.w32 | 2 +- ext/gd/gd.c | 743 ++++++++++++++++++++++----------------- ext/gd/gd_image_object.c | 83 ----- ext/gd/gd_image_object.h | 44 --- 5 files changed, 431 insertions(+), 445 deletions(-) delete mode 100644 ext/gd/gd_image_object.c delete mode 100644 ext/gd/gd_image_object.h diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index e0d4806f2ff4c..df3cab72323b1 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -166,7 +166,7 @@ dnl Various checks for GD features PHP_GD_FREETYPE2 PHP_GD_JISX0208 - PHP_NEW_EXTENSION(gd, gd.c gd_image_object.c $extra_sources, $ext_shared,, \\$(GD_CFLAGS)) + PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared,, \\$(GD_CFLAGS)) PHP_ADD_BUILD_DIR($ext_builddir/libgd) GD_CFLAGS="-I$ext_srcdir/libgd $GD_CFLAGS" GD_HEADER_DIRS="ext/gd/ ext/gd/libgd/" @@ -183,7 +183,7 @@ dnl Various checks for GD features AC_DEFINE(HAVE_LIBGD, 1, [ ]) PHP_GD_CHECK_VERSION - PHP_NEW_EXTENSION(gd, gd.c gd_image_object.c $extra_sources, $ext_shared) + PHP_NEW_EXTENSION(gd, gd.c $extra_sources, $ext_shared) GD_HEADER_DIRS="ext/gd/" PHP_CHECK_LIBRARY(gd, gdImageCreate, [], [ AC_MSG_ERROR([GD build test failed. Please check the config.log for details.]) diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index 5907af1136dd9..6695976d0e243 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -33,7 +33,7 @@ if (PHP_GD != "no") { CHECK_LIB("User32.lib", "gd", PHP_GD); CHECK_LIB("Gdi32.lib", "gd", PHP_GD); - EXTENSION("gd", "gd.c gd_image_object.c", null, "-Iext/gd/libgd", "php_gd2.dll"); + EXTENSION("gd", "gd.c", null, "-Iext/gd/libgd", "php_gd2.dll"); ADD_SOURCES("ext/gd/libgd", "gd2copypal.c gd.c \ gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \ gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \ diff --git a/ext/gd/gd.c b/ext/gd/gd.c index aed3a1ff0c86e..4edcc1fc4fc4b 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -33,7 +33,8 @@ #include "php_gd.h" #include "ext/standard/info.h" #include "php_open_temporary_file.h" -#include "gd_image_object.h" +#include "zend_object_handlers.h" +#include "zend_interfaces.h" #ifdef HAVE_SYS_WAIT_H # include @@ -131,166 +132,272 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()); static int _php_image_type(char data[12]); +/* output streaming (formerly gd_ctx.c) */ +static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()); + +/********************************************************* + * + * GD Object Representation + * + ********************************************************/ + +zend_class_entry *gd_image_ce; + +typedef struct _gd_ext_image_object { + gdImagePtr image; + zend_object std; +} php_gd_image_object; + +static zend_object_handlers php_gd_image_object_handlers; + +static const zend_function_entry gd_image_object_methods[] = { + PHP_FE_END +}; + +static zend_function *php_gd_image_object_get_constructor(zend_object *object) +{ + zend_throw_error(NULL, "You cannot initialize a GdImage object except through helper functions"); + return NULL; +} + +/** + * Returns the underlying php_gd_image_object from a zend_object + */ + +static zend_always_inline php_gd_image_object* php_gd_exgdimage_from_zobj_p(zend_object* obj) +{ + return (php_gd_image_object *) ((char *) (obj) - XtOffsetOf(php_gd_image_object, std)); +} + +/** + * Converts an extension GdImage instance contained within a zval into the gdImagePtr + * for use with library APIs + */ +static zend_always_inline gdImagePtr php_gd_libgdimageptr_from_zval_p(zval* zp) +{ + return php_gd_exgdimage_from_zobj_p(Z_OBJ_P(zp))->image; +} + + +zend_object *php_gd_image_object_create(zend_class_entry *class_type) +{ + size_t block_len = sizeof(php_gd_image_object) + zend_object_properties_size(class_type); + php_gd_image_object *intern = emalloc(block_len); + memset(intern, 0, block_len); + + zend_object_std_init(&intern->std, class_type); + object_properties_init(&intern->std, class_type); + intern->std.handlers = &php_gd_image_object_handlers; + + return &intern->std; +}; + +static void php_gd_image_object_free(zend_object *intern) +{ + php_gd_image_object *img_obj_ptr = php_gd_exgdimage_from_zobj_p(intern); + gdImageDestroy(img_obj_ptr->image); + img_obj_ptr->image = NULL; + + zend_object_std_dtor(intern); +}; + +/** + * Creates a new GdImage object wrapping the gdImagePtr and attaches it + * to the zval (usually return_value). + * + * This function must only be called once per valid gdImagePtr + */ +void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) +{ + object_init_ex(val, gd_image_ce); + php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; +} + +static void php_gd_object_minit_helper() +{ + zend_class_entry ce; + INIT_CLASS_ENTRY(ce, "GdImage", gd_image_object_methods); + gd_image_ce = zend_register_internal_class(&ce); + gd_image_ce->ce_flags |= ZEND_ACC_FINAL; + gd_image_ce->create_object = php_gd_image_object_create; + gd_image_ce->serialize = zend_class_serialize_deny; + gd_image_ce->unserialize = zend_class_unserialize_deny; + + /* setting up the object handlers for the GdImage class */ + memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); + php_gd_image_object_handlers.clone_obj = NULL; + php_gd_image_object_handlers.free_obj = php_gd_image_object_free; + php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; + php_gd_image_object_handlers.offset = XtOffsetOf(php_gd_image_object, std); +} + + +/********************************************************* + * + * Extension Implementation + * + ********************************************************/ + /* {{{ gd_functions[] */ static const zend_function_entry gd_functions[] = { - PHP_FE(gd_info, arginfo_gd_info) - PHP_FE(imagearc, arginfo_imagearc) - PHP_FE(imageellipse, arginfo_imageellipse) - PHP_FE(imagechar, arginfo_imagechar) - PHP_FE(imagecharup, arginfo_imagecharup) - PHP_FE(imagecolorat, arginfo_imagecolorat) - PHP_FE(imagecolorallocate, arginfo_imagecolorallocate) - PHP_FE(imagepalettecopy, arginfo_imagepalettecopy) - PHP_FE(imagecreatefromstring, arginfo_imagecreatefromstring) - PHP_FE(imagecolorclosest, arginfo_imagecolorclosest) - PHP_FE(imagecolorclosesthwb, arginfo_imagecolorclosesthwb) - PHP_FE(imagecolordeallocate, arginfo_imagecolordeallocate) - PHP_FE(imagecolorresolve, arginfo_imagecolorresolve) - PHP_FE(imagecolorexact, arginfo_imagecolorexact) - PHP_FE(imagecolorset, arginfo_imagecolorset) - PHP_FE(imagecolortransparent, arginfo_imagecolortransparent) - PHP_FE(imagecolorstotal, arginfo_imagecolorstotal) - PHP_FE(imagecolorsforindex, arginfo_imagecolorsforindex) - PHP_FE(imagecopy, arginfo_imagecopy) - PHP_FE(imagecopymerge, arginfo_imagecopymerge) - PHP_FE(imagecopymergegray, arginfo_imagecopymergegray) - PHP_FE(imagecopyresized, arginfo_imagecopyresized) - PHP_FE(imagecreate, arginfo_imagecreate) - PHP_FE(imagecreatetruecolor, arginfo_imagecreatetruecolor) - PHP_FE(imageistruecolor, arginfo_imageistruecolor) - PHP_FE(imagetruecolortopalette, arginfo_imagetruecolortopalette) - PHP_FE(imagepalettetotruecolor, arginfo_imagepalettetotruecolor) - PHP_FE(imagesetthickness, arginfo_imagesetthickness) - PHP_FE(imagefilledarc, arginfo_imagefilledarc) - PHP_FE(imagefilledellipse, arginfo_imagefilledellipse) - PHP_FE(imagealphablending, arginfo_imagealphablending) - PHP_FE(imagesavealpha, arginfo_imagesavealpha) - PHP_FE(imagecolorallocatealpha, arginfo_imagecolorallocatealpha) - PHP_FE(imagecolorresolvealpha, arginfo_imagecolorresolvealpha) - PHP_FE(imagecolorclosestalpha, arginfo_imagecolorclosestalpha) - PHP_FE(imagecolorexactalpha, arginfo_imagecolorexactalpha) - PHP_FE(imagecopyresampled, arginfo_imagecopyresampled) + PHP_FE(gd_info, arginfo_gd_info) + PHP_FE(imagearc, arginfo_imagearc) + PHP_FE(imageellipse, arginfo_imageellipse) + PHP_FE(imagechar, arginfo_imagechar) + PHP_FE(imagecharup, arginfo_imagecharup) + PHP_FE(imagecolorat, arginfo_imagecolorat) + PHP_FE(imagecolorallocate, arginfo_imagecolorallocate) + PHP_FE(imagepalettecopy, arginfo_imagepalettecopy) + PHP_FE(imagecreatefromstring, arginfo_imagecreatefromstring) + PHP_FE(imagecolorclosest, arginfo_imagecolorclosest) + PHP_FE(imagecolorclosesthwb, arginfo_imagecolorclosesthwb) + PHP_FE(imagecolordeallocate, arginfo_imagecolordeallocate) + PHP_FE(imagecolorresolve, arginfo_imagecolorresolve) + PHP_FE(imagecolorexact, arginfo_imagecolorexact) + PHP_FE(imagecolorset, arginfo_imagecolorset) + PHP_FE(imagecolortransparent, arginfo_imagecolortransparent) + PHP_FE(imagecolorstotal, arginfo_imagecolorstotal) + PHP_FE(imagecolorsforindex, arginfo_imagecolorsforindex) + PHP_FE(imagecopy, arginfo_imagecopy) + PHP_FE(imagecopymerge, arginfo_imagecopymerge) + PHP_FE(imagecopymergegray, arginfo_imagecopymergegray) + PHP_FE(imagecopyresized, arginfo_imagecopyresized) + PHP_FE(imagecreate, arginfo_imagecreate) + PHP_FE(imagecreatetruecolor, arginfo_imagecreatetruecolor) + PHP_FE(imageistruecolor, arginfo_imageistruecolor) + PHP_FE(imagetruecolortopalette, arginfo_imagetruecolortopalette) + PHP_FE(imagepalettetotruecolor, arginfo_imagepalettetotruecolor) + PHP_FE(imagesetthickness, arginfo_imagesetthickness) + PHP_FE(imagefilledarc, arginfo_imagefilledarc) + PHP_FE(imagefilledellipse, arginfo_imagefilledellipse) + PHP_FE(imagealphablending, arginfo_imagealphablending) + PHP_FE(imagesavealpha, arginfo_imagesavealpha) + PHP_FE(imagecolorallocatealpha, arginfo_imagecolorallocatealpha) + PHP_FE(imagecolorresolvealpha, arginfo_imagecolorresolvealpha) + PHP_FE(imagecolorclosestalpha, arginfo_imagecolorclosestalpha) + PHP_FE(imagecolorexactalpha, arginfo_imagecolorexactalpha) + PHP_FE(imagecopyresampled, arginfo_imagecopyresampled) #ifdef PHP_WIN32 - PHP_FE(imagegrabwindow, arginfo_imagegrabwindow) + PHP_FE(imagegrabwindow, arginfo_imagegrabwindow) PHP_FE(imagegrabscreen, arginfo_imagegrabscreen) #endif - PHP_FE(imagerotate, arginfo_imagerotate) - PHP_FE(imageflip, arginfo_imageflip) - - PHP_FE(imageantialias, arginfo_imageantialias) - PHP_FE(imagecrop, arginfo_imagecrop) - PHP_FE(imagecropauto, arginfo_imagecropauto) - PHP_FE(imagescale, arginfo_imagescale) - PHP_FE(imageaffine, arginfo_imageaffine) - PHP_FE(imageaffinematrixconcat, arginfo_imageaffinematrixconcat) - PHP_FE(imageaffinematrixget, arginfo_imageaffinematrixget) - PHP_FE(imagesetinterpolation, arginfo_imagesetinterpolation) - PHP_FE(imagesettile, arginfo_imagesettile) - PHP_FE(imagesetbrush, arginfo_imagesetbrush) - PHP_FE(imagesetstyle, arginfo_imagesetstyle) + PHP_FE(imagerotate, arginfo_imagerotate) + PHP_FE(imageflip, arginfo_imageflip) + + PHP_FE(imageantialias, arginfo_imageantialias) + PHP_FE(imagecrop, arginfo_imagecrop) + PHP_FE(imagecropauto, arginfo_imagecropauto) + PHP_FE(imagescale, arginfo_imagescale) + PHP_FE(imageaffine, arginfo_imageaffine) + PHP_FE(imageaffinematrixconcat, arginfo_imageaffinematrixconcat) + PHP_FE(imageaffinematrixget, arginfo_imageaffinematrixget) + PHP_FE(imagesetinterpolation, arginfo_imagesetinterpolation) + PHP_FE(imagesettile, arginfo_imagesettile) + PHP_FE(imagesetbrush, arginfo_imagesetbrush) + PHP_FE(imagesetstyle, arginfo_imagesetstyle) #ifdef HAVE_GD_PNG - PHP_FE(imagecreatefrompng, arginfo_imagecreatefrompng) + PHP_FE(imagecreatefrompng, arginfo_imagecreatefrompng) #endif #ifdef HAVE_GD_WEBP - PHP_FE(imagecreatefromwebp, arginfo_imagecreatefromwebp) + PHP_FE(imagecreatefromwebp, arginfo_imagecreatefromwebp) #endif - PHP_FE(imagecreatefromgif, arginfo_imagecreatefromgif) + PHP_FE(imagecreatefromgif, arginfo_imagecreatefromgif) #ifdef HAVE_GD_JPG - PHP_FE(imagecreatefromjpeg, arginfo_imagecreatefromjpeg) + PHP_FE(imagecreatefromjpeg, arginfo_imagecreatefromjpeg) #endif - PHP_FE(imagecreatefromwbmp, arginfo_imagecreatefromwbmp) - PHP_FE(imagecreatefromxbm, arginfo_imagecreatefromxbm) + PHP_FE(imagecreatefromwbmp, arginfo_imagecreatefromwbmp) + PHP_FE(imagecreatefromxbm, arginfo_imagecreatefromxbm) #if defined(HAVE_GD_XPM) - PHP_FE(imagecreatefromxpm, arginfo_imagecreatefromxpm) + PHP_FE(imagecreatefromxpm, arginfo_imagecreatefromxpm) #endif - PHP_FE(imagecreatefromgd, arginfo_imagecreatefromgd) - PHP_FE(imagecreatefromgd2, arginfo_imagecreatefromgd2) - PHP_FE(imagecreatefromgd2part, arginfo_imagecreatefromgd2part) + PHP_FE(imagecreatefromgd, arginfo_imagecreatefromgd) + PHP_FE(imagecreatefromgd2, arginfo_imagecreatefromgd2) + PHP_FE(imagecreatefromgd2part, arginfo_imagecreatefromgd2part) #ifdef HAVE_GD_BMP - PHP_FE(imagecreatefrombmp, arginfo_imagecreatefrombmp) + PHP_FE(imagecreatefrombmp, arginfo_imagecreatefrombmp) #endif #ifdef HAVE_GD_TGA - PHP_FE(imagecreatefromtga, arginfo_imagecreatefromtga) + PHP_FE(imagecreatefromtga, arginfo_imagecreatefromtga) #endif #ifdef HAVE_GD_PNG - PHP_FE(imagepng, arginfo_imagepng) + PHP_FE(imagepng, arginfo_imagepng) #endif #ifdef HAVE_GD_WEBP - PHP_FE(imagewebp, arginfo_imagewebp) + PHP_FE(imagewebp, arginfo_imagewebp) #endif - PHP_FE(imagegif, arginfo_imagegif) + PHP_FE(imagegif, arginfo_imagegif) #ifdef HAVE_GD_JPG - PHP_FE(imagejpeg, arginfo_imagejpeg) + PHP_FE(imagejpeg, arginfo_imagejpeg) #endif - PHP_FE(imagewbmp, arginfo_imagewbmp) - PHP_FE(imagegd, arginfo_imagegd) - PHP_FE(imagegd2, arginfo_imagegd2) + PHP_FE(imagewbmp, arginfo_imagewbmp) + PHP_FE(imagegd, arginfo_imagegd) + PHP_FE(imagegd2, arginfo_imagegd2) #ifdef HAVE_GD_BMP - PHP_FE(imagebmp, arginfo_imagebmp) + PHP_FE(imagebmp, arginfo_imagebmp) #endif - PHP_FE(imagedestroy, arginfo_imagedestroy) - PHP_FE(imagegammacorrect, arginfo_imagegammacorrect) - PHP_FE(imagefill, arginfo_imagefill) - PHP_FE(imagefilledpolygon, arginfo_imagefilledpolygon) - PHP_FE(imagefilledrectangle, arginfo_imagefilledrectangle) - PHP_FE(imagefilltoborder, arginfo_imagefilltoborder) - PHP_FE(imagefontwidth, arginfo_imagefontwidth) - PHP_FE(imagefontheight, arginfo_imagefontheight) - PHP_FE(imageinterlace, arginfo_imageinterlace) - PHP_FE(imageline, arginfo_imageline) - PHP_FE(imageloadfont, arginfo_imageloadfont) - PHP_FE(imagepolygon, arginfo_imagepolygon) - PHP_FE(imageopenpolygon, arginfo_imageopenpolygon) - PHP_FE(imagerectangle, arginfo_imagerectangle) - PHP_FE(imagesetpixel, arginfo_imagesetpixel) - PHP_FE(imagestring, arginfo_imagestring) - PHP_FE(imagestringup, arginfo_imagestringup) - PHP_FE(imagesx, arginfo_imagesx) - PHP_FE(imagesy, arginfo_imagesy) - PHP_FE(imagesetclip, arginfo_imagesetclip) - PHP_FE(imagegetclip, arginfo_imagegetclip) - PHP_FE(imagedashedline, arginfo_imagedashedline) + PHP_FE(imagedestroy, arginfo_imagedestroy) + PHP_FE(imagegammacorrect, arginfo_imagegammacorrect) + PHP_FE(imagefill, arginfo_imagefill) + PHP_FE(imagefilledpolygon, arginfo_imagefilledpolygon) + PHP_FE(imagefilledrectangle, arginfo_imagefilledrectangle) + PHP_FE(imagefilltoborder, arginfo_imagefilltoborder) + PHP_FE(imagefontwidth, arginfo_imagefontwidth) + PHP_FE(imagefontheight, arginfo_imagefontheight) + PHP_FE(imageinterlace, arginfo_imageinterlace) + PHP_FE(imageline, arginfo_imageline) + PHP_FE(imageloadfont, arginfo_imageloadfont) + PHP_FE(imagepolygon, arginfo_imagepolygon) + PHP_FE(imageopenpolygon, arginfo_imageopenpolygon) + PHP_FE(imagerectangle, arginfo_imagerectangle) + PHP_FE(imagesetpixel, arginfo_imagesetpixel) + PHP_FE(imagestring, arginfo_imagestring) + PHP_FE(imagestringup, arginfo_imagestringup) + PHP_FE(imagesx, arginfo_imagesx) + PHP_FE(imagesy, arginfo_imagesy) + PHP_FE(imagesetclip, arginfo_imagesetclip) + PHP_FE(imagegetclip, arginfo_imagegetclip) + PHP_FE(imagedashedline, arginfo_imagedashedline) #ifdef HAVE_GD_FREETYPE - PHP_FE(imagettfbbox, arginfo_imagettfbbox) + PHP_FE(imagettfbbox, arginfo_imagettfbbox) PHP_FE(imagettftext, arginfo_imagettftext) PHP_FE(imageftbbox, arginfo_imageftbbox) PHP_FE(imagefttext, arginfo_imagefttext) #endif - PHP_FE(imagetypes, arginfo_imagetypes) + PHP_FE(imagetypes, arginfo_imagetypes) - PHP_FE(imagelayereffect, arginfo_imagelayereffect) - PHP_FE(imagexbm, arginfo_imagexbm) + PHP_FE(imagelayereffect, arginfo_imagelayereffect) + PHP_FE(imagexbm, arginfo_imagexbm) - PHP_FE(imagecolormatch, arginfo_imagecolormatch) + PHP_FE(imagecolormatch, arginfo_imagecolormatch) /* gd filters */ - PHP_FE(imagefilter, arginfo_imagefilter) - PHP_FE(imageconvolution, arginfo_imageconvolution) + PHP_FE(imagefilter, arginfo_imagefilter) + PHP_FE(imageconvolution, arginfo_imageconvolution) - PHP_FE(imageresolution, arginfo_imageresolution) + PHP_FE(imageresolution, arginfo_imageresolution) - PHP_FE_END + PHP_FE_END }; /* }}} */ zend_module_entry gd_module_entry = { - STANDARD_MODULE_HEADER, - "gd", - gd_functions, - PHP_MINIT(gd), - PHP_MSHUTDOWN(gd), - NULL, - PHP_RSHUTDOWN(gd), - PHP_MINFO(gd), - PHP_GD_VERSION, - STANDARD_MODULE_PROPERTIES + STANDARD_MODULE_HEADER, + "gd", + gd_functions, + PHP_MINIT(gd), + PHP_MSHUTDOWN(gd), + NULL, + PHP_RSHUTDOWN(gd), + PHP_MINFO(gd), + PHP_GD_VERSION, + STANDARD_MODULE_PROPERTIES }; #ifdef COMPILE_DL_GD @@ -299,211 +406,13 @@ ZEND_GET_MODULE(gd) /* {{{ PHP_INI_BEGIN */ PHP_INI_BEGIN() - PHP_INI_ENTRY("gd.jpeg_ignore_warning", "1", PHP_INI_ALL, NULL) +PHP_INI_ENTRY("gd.jpeg_ignore_warning", "1", PHP_INI_ALL, NULL) PHP_INI_END() /* }}} */ - -#define CTX_PUTC(c,ctx) ctx->putC(ctx, c) - - static void _php_image_output_putc(struct gdIOCtx *ctx, int c) /* {{{ */ -{ - /* without the following downcast, the write will fail - * (i.e., will write a zero byte) for all - * big endian architectures: - */ - unsigned char ch = (unsigned char) c; - php_write(&ch, 1); -} /* }}} */ - -static int _php_image_output_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ -{ - return php_write((void *)buf, l); -} /* }}} */ - -static void _php_image_output_ctxfree(struct gdIOCtx *ctx) /* {{{ */ -{ - if(ctx) { - efree(ctx); - } -} /* }}} */ - -static void _php_image_stream_putc(struct gdIOCtx *ctx, int c) /* {{{ */ { - char ch = (char) c; - php_stream * stream = (php_stream *)ctx->data; - php_stream_write(stream, &ch, 1); -} /* }}} */ - -static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ -{ - php_stream * stream = (php_stream *)ctx->data; - return php_stream_write(stream, (void *)buf, l); -} /* }}} */ - -static void _php_image_stream_ctxfree(struct gdIOCtx *ctx) /* {{{ */ -{ - if(ctx->data) { - ctx->data = NULL; - } - if(ctx) { - efree(ctx); - } -} /* }}} */ - -static void _php_image_stream_ctxfreeandclose(struct gdIOCtx *ctx) /* {{{ */ -{ - - if(ctx->data) { - php_stream_close((php_stream *) ctx->data); - ctx->data = NULL; - } - if(ctx) { - efree(ctx); - } -} /* }}} */ - -/* {{{ _php_image_output_ctx */ -static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) -{ - zval *imgind; - char *file = NULL; - size_t file_len = 0; - zend_long quality, basefilter; - zend_bool compressed = 1; - gdImagePtr im; - int argc = ZEND_NUM_ARGS(); - int q = -1, i; - int f = -1; - gdIOCtx *ctx = NULL; - zval *to_zval = NULL; - php_stream *stream; - int close_stream = 1; - - /* The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called - * from imagey(). - */ - switch (image_type) { - case PHP_GDIMG_TYPE_XBM: - if (zend_parse_parameters(argc, "Op!|ll", &imgind, gd_image_ce, &file, &file_len, &quality, &basefilter) == FAILURE) { - return; - } - break; - case PHP_GDIMG_TYPE_BMP: - if (zend_parse_parameters(argc, "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) { - return; - } - break; - default: - /* PHP_GDIMG_TYPE_GIF - * PHP_GDIMG_TYPE_PNG - * PHP_GDIMG_TYPE_JPG - * PHP_GDIMG_TYPE_WBM - * PHP_GDIMG_TYPE_WEBP - * */ - if (zend_parse_parameters(argc, "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &basefilter) == FAILURE) { - return; - } - } - - im = php_gd_libgdimageptr_from_zval_p(imgind); - - if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3) { - q = quality; /* or colorindex for foreground of BW images (defaults to black) */ - if (argc == 4) { - f = basefilter; - } - } - - if (argc > 1 && to_zval != NULL) { - if (Z_TYPE_P(to_zval) == IS_RESOURCE) { - php_stream_from_zval_no_verify(stream, to_zval); - if (stream == NULL) { - RETURN_FALSE; - } - close_stream = 0; - } else if (Z_TYPE_P(to_zval) == IS_STRING) { - if (CHECK_ZVAL_NULL_PATH(to_zval)) { - zend_type_error("Invalid 2nd parameter, filename must not contain null bytes"); - return; - } - - stream = php_stream_open_wrapper(Z_STRVAL_P(to_zval), "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); - if (stream == NULL) { - RETURN_FALSE; - } - } else { - php_error_docref(NULL, E_WARNING, "Invalid 2nd parameter, it must a filename or a stream"); - RETURN_FALSE; - } - } else if (argc > 1 && file != NULL) { - stream = php_stream_open_wrapper(file, "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); - if (stream == NULL) { - RETURN_FALSE; - } - } else { - ctx = ecalloc(1, sizeof(gdIOCtx)); - ctx->putC = _php_image_output_putc; - ctx->putBuf = _php_image_output_putbuf; - ctx->gd_free = _php_image_output_ctxfree; - } - - if (!ctx) { - ctx = ecalloc(1, sizeof(gdIOCtx)); - ctx->putC = _php_image_stream_putc; - ctx->putBuf = _php_image_stream_putbuf; - if (close_stream) { - ctx->gd_free = _php_image_stream_ctxfreeandclose; - } else { - ctx->gd_free = _php_image_stream_ctxfree; - } - ctx->data = (void *)stream; - } - - switch(image_type) { - case PHP_GDIMG_TYPE_JPG: - (*func_p)(im, ctx, q); - break; - case PHP_GDIMG_TYPE_WEBP: - if (q == -1) { - q = 80; - } - (*func_p)(im, ctx, q); - break; - case PHP_GDIMG_TYPE_PNG: - (*func_p)(im, ctx, q, f); - break; - case PHP_GDIMG_TYPE_XBM: - case PHP_GDIMG_TYPE_WBM: - if (argc < 3) { - for(i=0; i < gdImageColorsTotal(im); i++) { - if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; - } - q = i; - } - if (image_type == PHP_GDIMG_TYPE_XBM) { - (*func_p)(im, file ? file : "", q, ctx); - } else { - (*func_p)(im, q, ctx); - } - break; - case PHP_GDIMG_TYPE_BMP: - (*func_p)(im, ctx, (int) compressed); - break; - default: - (*func_p)(im, ctx); - break; - } - - ctx->gd_free(ctx); - - RETURN_TRUE; -} -/* }}} */ - - /* {{{ php_free_gd_font */ -static void php_free_gd_font(zend_resource *rsrc) + static void php_free_gd_font(zend_resource *rsrc) { gdFontPtr fp = (gdFontPtr) rsrc->ptr; @@ -519,7 +428,6 @@ static void php_free_gd_font(zend_resource *rsrc) */ void php_gd_error_method(int type, const char *format, va_list args) { - switch (type) { #ifndef PHP_WIN32 case GD_DEBUG: @@ -4260,3 +4168,208 @@ PHP_FUNCTION(imageresolution) } } /* }}} */ + + +/********************************************************* + * + * Stream Handling + * Formerly contained within ext/gd/gd_ctx.c and included + * at the the top of this file + * + ********************************************************/ + +#define CTX_PUTC(c,ctx) ctx->putC(ctx, c) + +static void _php_image_output_putc(struct gdIOCtx *ctx, int c) /* {{{ */ +{ + /* without the following downcast, the write will fail + * (i.e., will write a zero byte) for all + * big endian architectures: + */ + unsigned char ch = (unsigned char) c; + php_write(&ch, 1); +} /* }}} */ + +static int _php_image_output_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ +{ + return php_write((void *)buf, l); +} /* }}} */ + +static void _php_image_output_ctxfree(struct gdIOCtx *ctx) /* {{{ */ +{ + if(ctx) { + efree(ctx); + } +} /* }}} */ + +static void _php_image_stream_putc(struct gdIOCtx *ctx, int c) /* {{{ */ { + char ch = (char) c; + php_stream * stream = (php_stream *)ctx->data; + php_stream_write(stream, &ch, 1); +} /* }}} */ + +static int _php_image_stream_putbuf(struct gdIOCtx *ctx, const void* buf, int l) /* {{{ */ +{ + php_stream * stream = (php_stream *)ctx->data; + return php_stream_write(stream, (void *)buf, l); +} /* }}} */ + +static void _php_image_stream_ctxfree(struct gdIOCtx *ctx) /* {{{ */ +{ + if(ctx->data) { + ctx->data = NULL; + } + if(ctx) { + efree(ctx); + } +} /* }}} */ + +static void _php_image_stream_ctxfreeandclose(struct gdIOCtx *ctx) /* {{{ */ +{ + + if(ctx->data) { + php_stream_close((php_stream *) ctx->data); + ctx->data = NULL; + } + if(ctx) { + efree(ctx); + } +} /* }}} */ + +/* {{{ _php_image_output_ctx */ +static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) +{ + zval *imgind; + char *file = NULL; + size_t file_len = 0; + zend_long quality, basefilter; + zend_bool compressed = 1; + gdImagePtr im; + int argc = ZEND_NUM_ARGS(); + int q = -1, i; + int f = -1; + gdIOCtx *ctx = NULL; + zval *to_zval = NULL; + php_stream *stream; + int close_stream = 1; + + /* The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called + * from imagey(). + */ + switch (image_type) { + case PHP_GDIMG_TYPE_XBM: + if (zend_parse_parameters(argc, "Op!|ll", &imgind, gd_image_ce, &file, &file_len, &quality, &basefilter) == FAILURE) { + return; + } + break; + case PHP_GDIMG_TYPE_BMP: + if (zend_parse_parameters(argc, "O|z!b", &imgind, gd_image_ce, &to_zval, &compressed) == FAILURE) { + return; + } + break; + default: + /* PHP_GDIMG_TYPE_GIF + * PHP_GDIMG_TYPE_PNG + * PHP_GDIMG_TYPE_JPG + * PHP_GDIMG_TYPE_WBM + * PHP_GDIMG_TYPE_WEBP + * */ + if (zend_parse_parameters(argc, "O|z!ll", &imgind, gd_image_ce, &to_zval, &quality, &basefilter) == FAILURE) { + return; + } + } + + im = php_gd_libgdimageptr_from_zval_p(imgind); + + if (image_type != PHP_GDIMG_TYPE_BMP && argc >= 3) { + q = quality; /* or colorindex for foreground of BW images (defaults to black) */ + if (argc == 4) { + f = basefilter; + } + } + + if (argc > 1 && to_zval != NULL) { + if (Z_TYPE_P(to_zval) == IS_RESOURCE) { + php_stream_from_zval_no_verify(stream, to_zval); + if (stream == NULL) { + RETURN_FALSE; + } + close_stream = 0; + } else if (Z_TYPE_P(to_zval) == IS_STRING) { + if (CHECK_ZVAL_NULL_PATH(to_zval)) { + zend_type_error("Invalid 2nd parameter, filename must not contain null bytes"); + return; + } + + stream = php_stream_open_wrapper(Z_STRVAL_P(to_zval), "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); + if (stream == NULL) { + RETURN_FALSE; + } + } else { + php_error_docref(NULL, E_WARNING, "Invalid 2nd parameter, it must a filename or a stream"); + RETURN_FALSE; + } + } else if (argc > 1 && file != NULL) { + stream = php_stream_open_wrapper(file, "wb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); + if (stream == NULL) { + RETURN_FALSE; + } + } else { + ctx = ecalloc(1, sizeof(gdIOCtx)); + ctx->putC = _php_image_output_putc; + ctx->putBuf = _php_image_output_putbuf; + ctx->gd_free = _php_image_output_ctxfree; + } + + if (!ctx) { + ctx = ecalloc(1, sizeof(gdIOCtx)); + ctx->putC = _php_image_stream_putc; + ctx->putBuf = _php_image_stream_putbuf; + if (close_stream) { + ctx->gd_free = _php_image_stream_ctxfreeandclose; + } else { + ctx->gd_free = _php_image_stream_ctxfree; + } + ctx->data = (void *)stream; + } + + switch(image_type) { + case PHP_GDIMG_TYPE_JPG: + (*func_p)(im, ctx, q); + break; + case PHP_GDIMG_TYPE_WEBP: + if (q == -1) { + q = 80; + } + (*func_p)(im, ctx, q); + break; + case PHP_GDIMG_TYPE_PNG: + (*func_p)(im, ctx, q, f); + break; + case PHP_GDIMG_TYPE_XBM: + case PHP_GDIMG_TYPE_WBM: + if (argc < 3) { + for(i=0; i < gdImageColorsTotal(im); i++) { + if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break; + } + q = i; + } + if (image_type == PHP_GDIMG_TYPE_XBM) { + (*func_p)(im, file ? file : "", q, ctx); + } else { + (*func_p)(im, q, ctx); + } + break; + case PHP_GDIMG_TYPE_BMP: + (*func_p)(im, ctx, (int) compressed); + break; + default: + (*func_p)(im, ctx); + break; + } + + ctx->gd_free(ctx); + + RETURN_TRUE; +} +/* }}} */ \ No newline at end of file diff --git a/ext/gd/gd_image_object.c b/ext/gd/gd_image_object.c deleted file mode 100644 index c23fc44037454..0000000000000 --- a/ext/gd/gd_image_object.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Mark Randall | - +----------------------------------------------------------------------+ - */ - -#include "gd_image_object.h" -#include "gd_arginfo.h" -#include "zend.h" -#include "zend_interfaces.h" -#include "../../Zend/zend.h" - -/* - * List of unique methods implemented by GdImage - */ - -static zend_object_handlers php_gd_image_object_handlers; - -static const zend_function_entry gd_image_object_methods[] = { - PHP_FE_END -}; - -static zend_function *php_gd_image_object_get_constructor(zend_object *object) -{ - zend_throw_error(NULL, "You cannot initialize a GdImage object except through helper functions"); - return NULL; -} - -zend_object *php_gd_image_object_create(zend_class_entry *class_type) -{ - size_t block_len = sizeof(php_gd_image_object) + zend_object_properties_size(class_type); - php_gd_image_object *intern = emalloc(block_len); - memset(intern, 0, block_len); - - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); - intern->std.handlers = &php_gd_image_object_handlers; - - return &intern->std; -}; - -static void php_gd_image_object_free(zend_object *intern) -{ - php_gd_image_object *img_obj_ptr = php_gd_exgdimage_from_zobj_p(intern); - gdImageDestroy(img_obj_ptr->image); - img_obj_ptr->image = NULL; - - zend_object_std_dtor(intern); -}; - -void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) -{ - object_init_ex(val, gd_image_ce); - php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; -} - -void php_gd_object_minit_helper() -{ - zend_class_entry ce; - INIT_CLASS_ENTRY(ce, "GdImage", gd_image_object_methods); - gd_image_ce = zend_register_internal_class(&ce); - gd_image_ce->ce_flags |= ZEND_ACC_FINAL; - gd_image_ce->create_object = php_gd_image_object_create; - gd_image_ce->serialize = zend_class_serialize_deny; - gd_image_ce->unserialize = zend_class_unserialize_deny; - - /* setting up the object handlers for the GdImage class */ - memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); - php_gd_image_object_handlers.clone_obj = NULL; - php_gd_image_object_handlers.free_obj = php_gd_image_object_free; - php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; - php_gd_image_object_handlers.offset = XtOffsetOf(php_gd_image_object, std); -} diff --git a/ext/gd/gd_image_object.h b/ext/gd/gd_image_object.h deleted file mode 100644 index 091a04e6d8c18..0000000000000 --- a/ext/gd/gd_image_object.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Mark Randall | - +----------------------------------------------------------------------+ - */ - -#ifndef SRC_GD_IMAGE_OBJECT_H -#define SRC_GD_IMAGE_OBJECT_H - -#include -#include - -zend_class_entry *gd_image_ce; - -typedef struct _gd_ext_image_object { - gdImagePtr image; - zend_object std; -} php_gd_image_object; - -void php_gd_object_minit_helper(); - -static zend_always_inline php_gd_image_object* php_gd_exgdimage_from_zobj_p(zend_object* obj) -{ - return (php_gd_image_object *) ((char *) (obj) - XtOffsetOf(php_gd_image_object, std)); -} - -static zend_always_inline gdImagePtr php_gd_libgdimageptr_from_zval_p(zval* zp) -{ - return php_gd_exgdimage_from_zobj_p(Z_OBJ_P(zp))->image; -} - -void php_gd_assign_libgdimageptr_as_extgdimage(zval* val, gdImagePtr image); - -#endif //SRC_GD_IMAGE_OBJECT_H