--- embedaddon/php/ext/gd/gd.c 2012/02/21 23:47:56 1.1.1.1 +++ embedaddon/php/ext/gd/gd.c 2013/07/22 01:31:50 1.1.1.3 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2012 The PHP Group | + | Copyright (c) 1997-2013 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 | @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: gd.c,v 1.1.1.1 2012/02/21 23:47:56 misho Exp $ */ +/* $Id: gd.c,v 1.1.1.3 2013/07/22 01:31:50 misho Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -351,6 +351,12 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefrompng, 0) ZEND_END_ARG_INFO() #endif +#ifdef HAVE_GD_WEBP +ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromwebp, 0) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() +#endif + #ifdef HAVE_GD_XBM ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0) ZEND_ARG_INFO(0, filename) @@ -409,6 +415,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepng, 0, 0, 1) ZEND_END_ARG_INFO() #endif +#ifdef HAVE_GD_WEBP +ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewebp, 0, 0, 1) + ZEND_ARG_INFO(0, im) + ZEND_ARG_INFO(0, filename) +ZEND_END_ARG_INFO() +#endif + #ifdef HAVE_GD_JPG ZEND_BEGIN_ARG_INFO_EX(arginfo_imagejpeg, 0, 0, 1) ZEND_ARG_INFO(0, im) @@ -498,12 +511,13 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexact, 0) ZEND_ARG_INFO(0, blue) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(arginfo_imagecolorset, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorset, 0, 0, 5) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, color) ZEND_ARG_INFO(0, red) ZEND_ARG_INFO(0, green) ZEND_ARG_INFO(0, blue) + ZEND_ARG_INFO(0, alpha) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO(arginfo_imagecolorsforindex, 0) @@ -945,6 +959,9 @@ const zend_function_entry gd_functions[] = { #ifdef HAVE_GD_PNG PHP_FE(imagecreatefrompng, arginfo_imagecreatefrompng) #endif +#ifdef HAVE_GD_WEBP + PHP_FE(imagecreatefromwebp, arginfo_imagecreatefromwebp) +#endif #ifdef HAVE_GD_GIF_READ PHP_FE(imagecreatefromgif, arginfo_imagecreatefromgif) #endif @@ -968,6 +985,9 @@ const zend_function_entry gd_functions[] = { #ifdef HAVE_GD_PNG PHP_FE(imagepng, arginfo_imagepng) #endif +#ifdef HAVE_GD_WEBP + PHP_FE(imagewebp, arginfo_imagewebp) +#endif #ifdef HAVE_GD_GIF_CREATE PHP_FE(imagegif, arginfo_imagegif) #endif @@ -1241,9 +1261,13 @@ PHP_RSHUTDOWN_FUNCTION(gd) /* }}} */ #if HAVE_GD_BUNDLED -#define PHP_GD_VERSION_STRING "bundled (2.0.34 compatible)" +#define PHP_GD_VERSION_STRING "bundled (2.1.0 compatible)" #else -#define PHP_GD_VERSION_STRING "2.0" +# ifdef GD_VERSION_STRING +# define PHP_GD_VERSION_STRING GD_VERSION_STRING +# else +# define PHP_GD_VERSION_STRING "2.0" +# endif #endif /* {{{ PHP_MINFO_FUNCTION @@ -1308,6 +1332,11 @@ PHP_MINFO_FUNCTION(gd) #endif #if defined(HAVE_GD_XPM) && defined(HAVE_GD_BUNDLED) php_info_print_table_row(2, "XPM Support", "enabled"); + { + char tmp[12]; + snprintf(tmp, sizeof(tmp), "%d", XpmLibraryVersion()); + php_info_print_table_row(2, "libXpm Version", tmp); + } #endif #ifdef HAVE_GD_XBM php_info_print_table_row(2, "XBM Support", "enabled"); @@ -1470,7 +1499,7 @@ PHP_FUNCTION(imageloadfont) return; } - stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL); + stream = php_stream_open_wrapper(file, "rb", IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL); if (stream == NULL) { RETURN_FALSE; } @@ -1559,7 +1588,7 @@ PHP_FUNCTION(imageloadfont) * that overlap with the old fonts (with indices 1-5). The first * list index given out is always 1. */ - ind = 5 + zend_list_insert(font, le_gd_font); + ind = 5 + zend_list_insert(font, le_gd_font TSRMLS_CC); RETURN_LONG(ind); } @@ -2422,7 +2451,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_P } } - stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); + stream = php_stream_open_wrapper(file, "rb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL); if (stream == NULL) { RETURN_FALSE; } @@ -2431,6 +2460,23 @@ static void _php_image_create_from(INTERNAL_FUNCTION_P ioctx_func_p = NULL; /* don't allow sockets without IOCtx */ #endif + if (image_type == PHP_GDIMG_TYPE_WEBP) { + size_t buff_size; + char *buff; + + /* needs to be malloc (persistent) - GD will free() it later */ + buff_size = php_stream_copy_to_mem(stream, &buff, PHP_STREAM_COPY_ALL, 1); + if (!buff_size) { + php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot read image data"); + goto out_err; + } + im = (*ioctx_func_p)(buff_size, buff); + if (!im) { + goto out_err; + } + goto register_im; + } + /* try and avoid allocating a FILE* if the stream is not naturally a FILE* */ if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) { if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS)) { @@ -2508,6 +2554,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_P fflush(fp); } +register_im: if (im) { ZEND_REGISTER_RESOURCE(return_value, im, le_gd); php_stream_close(stream); @@ -2552,6 +2599,16 @@ PHP_FUNCTION(imagecreatefrompng) /* }}} */ #endif /* HAVE_GD_PNG */ +#ifdef HAVE_GD_WEBP +/* {{{ proto resource imagecreatefrompng(string filename) + Create a new image from PNG file or URL */ +PHP_FUNCTION(imagecreatefromwebp) +{ + _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "WEBP", gdImageCreateFromWebpPtr, gdImageCreateFromWebpPtr); +} +/* }}} */ +#endif /* HAVE_GD_VPX */ + #ifdef HAVE_GD_XBM /* {{{ proto resource imagecreatefromxbm(string filename) Create a new image from XBM file or URL */ @@ -2625,7 +2682,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAME /* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */ /* The quality parameter for gd2 stands for chunk size */ - if (zend_parse_parameters(argc TSRMLS_CC, "r|sll", &imgind, &file, &file_len, &quality, &type) == FAILURE) { + if (zend_parse_parameters(argc TSRMLS_CC, "r|pll", &imgind, &file, &file_len, &quality, &type) == FAILURE) { return; } @@ -2642,9 +2699,6 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAME } if (argc >= 2 && file_len) { - if (strlen(file) != file_len) { - RETURN_FALSE; - } PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename"); fp = VCWD_FOPEN(fn, "wb"); @@ -2786,11 +2840,7 @@ PHP_FUNCTION(imagexbm) Output GIF image to browser or file */ PHP_FUNCTION(imagegif) { -#ifdef HAVE_GD_GIF_CTX _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGifCtx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGif); -#endif } /* }}} */ #endif /* HAVE_GD_GIF_CREATE */ @@ -2800,25 +2850,29 @@ PHP_FUNCTION(imagegif) Output PNG image to browser or file */ PHP_FUNCTION(imagepng) { -#ifdef USE_GD_IOCTX _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng); -#endif } /* }}} */ #endif /* HAVE_GD_PNG */ + +#ifdef HAVE_GD_WEBP +/* {{{ proto bool imagewebp(resource im [, string filename[, quality]] ) + Output PNG image to browser or file */ +PHP_FUNCTION(imagewebp) +{ + _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "WEBP", gdImageWebpCtx); +} +/* }}} */ +#endif /* HAVE_GD_WEBP */ + + #ifdef HAVE_GD_JPG /* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]]) Output JPEG image to browser or file */ PHP_FUNCTION(imagejpeg) { -#ifdef USE_GD_IOCTX _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpegCtx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpeg); -#endif } /* }}} */ #endif /* HAVE_GD_JPG */ @@ -2828,11 +2882,7 @@ PHP_FUNCTION(imagejpeg) Output WBMP image to browser or file */ PHP_FUNCTION(imagewbmp) { -#ifdef USE_GD_IOCTX _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMPCtx); -#else - _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMP); -#endif } /* }}} */ #endif /* HAVE_GD_WBMP */ @@ -3061,11 +3111,11 @@ PHP_FUNCTION(imagecolorexact) PHP_FUNCTION(imagecolorset) { zval *IM; - long color, red, green, blue; + long color, red, green, blue, alpha = 0; int col; gdImagePtr im; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &color, &red, &green, &blue) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &IM, &color, &red, &green, &blue, &alpha) == FAILURE) { return; } @@ -3077,6 +3127,7 @@ PHP_FUNCTION(imagecolorset) im->red[col] = red; im->green[col] = green; im->blue[col] = blue; + im->alpha[col] = alpha; } else { RETURN_FALSE; } @@ -4096,7 +4147,7 @@ PHP_FUNCTION(imagepscopyfont) } nf_ind->extend = 1; - l_ind = zend_list_insert(nf_ind, le_ps_font); + l_ind = zend_list_insert(nf_ind, le_ps_font TSRMLS_CC); RETURN_LONG(l_ind); } */ @@ -4145,7 +4196,7 @@ PHP_FUNCTION(imagepsencodefont) RETURN_FALSE; } - zend_list_insert(enc_vector, le_ps_enc); + zend_list_insert(enc_vector, le_ps_enc TSRMLS_CC); RETURN_TRUE; } @@ -4550,7 +4601,7 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAM long ignore_warning; #endif - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sslll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pplll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) { return; } @@ -4559,14 +4610,6 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAM dest_height = height; dest_width = width; int_threshold = threshold; - - if (strlen(f_org) != f_org_len) { - RETURN_FALSE; - } - - if (strlen(f_dest) != f_dest_len) { - RETURN_FALSE; - } /* Check threshold value */ if (int_threshold < 0 || int_threshold > 8) {