--- embedaddon/php/ext/standard/image.c 2012/02/21 23:48:02 1.1 +++ embedaddon/php/ext/standard/image.c 2013/07/22 01:44:16 1.1.1.2.2.1 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: image.c,v 1.1 2012/02/21 23:48:02 misho Exp $ */ +/* $Id: image.c,v 1.1.1.2.2.1 2013/07/22 01:44:16 misho Exp $ */ #include "php.h" #include @@ -31,7 +31,9 @@ #endif #include "php_image.h" +#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) #include "zlib.h" +#endif /* file type markers */ PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'}; @@ -79,7 +81,9 @@ PHP_MINIT_FUNCTION(imagetypes) REGISTER_LONG_CONSTANT("IMAGETYPE_JP2", IMAGE_FILETYPE_JP2, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_JPX", IMAGE_FILETYPE_JPX, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_JB2", IMAGE_FILETYPE_JB2, CONST_CS | CONST_PERSISTENT); +#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) REGISTER_LONG_CONSTANT("IMAGETYPE_SWC", IMAGE_FILETYPE_SWC, CONST_CS | CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT("IMAGETYPE_IFF", IMAGE_FILETYPE_IFF, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP", IMAGE_FILETYPE_WBMP, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG2000",IMAGE_FILETYPE_JPC, CONST_CS | CONST_PERSISTENT); /* keep alias */ @@ -184,6 +188,7 @@ static unsigned long int php_swf_get_bits (unsigned ch } /* }}} */ +#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) /* {{{ php_handle_swc */ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) @@ -254,6 +259,7 @@ static struct gfxinfo *php_handle_swc(php_stream * str return result; } /* }}} */ +#endif /* {{{ php_handle_swf */ @@ -1283,27 +1289,12 @@ PHPAPI int php_getimagetype(php_stream * stream, char } /* }}} */ -/* {{{ proto array getimagesize(string imagefile [, array info]) - Get the size of an image as 4-element array */ -PHP_FUNCTION(getimagesize) +static void php_getimagesize_from_stream(php_stream *stream, zval **info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ { - zval **info = NULL; - char *arg1, *temp; - int arg1_len, itype = 0, argc = ZEND_NUM_ARGS(); + char *temp; + int itype = 0; struct gfxinfo *result = NULL; - php_stream * stream = NULL; - if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &arg1, &arg1_len, &info) == FAILURE) { - return; - } - - if (argc == 2) { - zval_dtor(*info); - array_init(*info); - } - - stream = php_stream_open_wrapper(arg1, "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL); - if (!stream) { RETURN_FALSE; } @@ -1327,7 +1318,11 @@ PHP_FUNCTION(getimagesize) result = php_handle_swf(stream TSRMLS_CC); break; case IMAGE_FILETYPE_SWC: +#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) result = php_handle_swc(stream TSRMLS_CC); +#else + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "The image is a compressed SWF file, but you do not have a static version of the zlib extension enabled"); +#endif break; case IMAGE_FILETYPE_PSD: result = php_handle_psd(stream TSRMLS_CC); @@ -1364,8 +1359,6 @@ PHP_FUNCTION(getimagesize) break; } - php_stream_close(stream); - if (result) { array_init(return_value); add_index_long(return_value, 0, result->width); @@ -1387,6 +1380,56 @@ PHP_FUNCTION(getimagesize) } } /* }}} */ + +#define FROM_DATA 0 +#define FROM_PATH 1 + +static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) { /* {{{ */ + zval **info = NULL; + php_stream *stream = NULL; + char *input; + int input_len; + const int argc = ZEND_NUM_ARGS(); + + if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &input, &input_len, &info) == FAILURE) { + return; + } + + if (argc == 2) { + zval_dtor(*info); + array_init(*info); + } + + + if (mode == FROM_PATH) { + stream = php_stream_open_wrapper(input, "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH, NULL); + } else { + stream = php_stream_memory_open(TEMP_STREAM_READONLY, input, input_len); + } + + if (!stream) { + RETURN_FALSE; + } + + php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU); + php_stream_close(stream); +} +/* }}} */ + +/* {{{ proto array getimagesize(string imagefile [, array info]) + Get the size of an image as 4-element array */ +PHP_FUNCTION(getimagesize) +{ + php_getimagesize_from_any(INTERNAL_FUNCTION_PARAM_PASSTHRU, FROM_PATH); +} +/* }}} */ + +/* {{{ proto array getimagesizefromstring(string data [, array info]) + Get the size of an image as 4-element array */ +PHP_FUNCTION(getimagesizefromstring) +{ + php_getimagesize_from_any(INTERNAL_FUNCTION_PARAM_PASSTHRU, FROM_DATA); +} /* * Local variables: