--- ext/standard/php_image.h.orig	2009-10-26 13:21:00.000000000 -0700
+++ ext/standard/php_image.h	2010-02-16 13:37:15.000000000 -0800
@@ -23,6 +23,7 @@
 #define PHP_IMAGE_H
 
 PHP_FUNCTION(getimagesize);
+PHP_FUNCTION(getimagesizefromstring);
 
 PHP_FUNCTION(image_type_to_mime_type);
 PHP_FUNCTION(image_type_to_extension);
--- ext/standard/basic_functions.c.orig	2009-10-26 13:21:00.000000000 -0700
+++ ext/standard/basic_functions.c	2010-02-16 13:37:15.000000000 -0800
@@ -2687,6 +2687,7 @@
 	PHP_FE(iptcparse,														arginfo_iptcparse)
 	PHP_FE(iptcembed,														arginfo_iptcembed)
 	PHP_FE(getimagesize,													arginfo_getimagesize)
+	PHP_FE(getimagesizefromstring,											arginfo_getimagesize)
 	PHP_FE(image_type_to_mime_type,											arginfo_image_type_to_mime_type)
 	PHP_FE(image_type_to_extension,											arginfo_image_type_to_extension)
 
--- ext/standard/image.c.orig	2009-10-26 13:21:00.000000000 -0700
+++ ext/standard/image.c	2010-02-16 13:38:44.000000000 -0800
@@ -1294,26 +1294,12 @@
 }
 /* }}} */
 
-/* {{{ proto array getimagesize(string imagefile [, array info])
-   Get the size of an image as 4-element array */
-PHP_FUNCTION(getimagesize)
+/* {{{ proto static void php_getimagesize_from_stream(php_stream *stream, zval **info, INTERNAL_FUNCTION_PARAMETERS) */
+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();
 	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;
@@ -1379,8 +1365,6 @@
 			break;
 	}
 
-	php_stream_close(stream);
-
 	if (result) {
 		array_init(return_value);
 		add_index_long(return_value, 0, result->width);
@@ -1403,6 +1387,81 @@
 }
 /* }}} */
 
+/* {{{ proto array getimagesize(string imagefile [, array info])
+   Get the size of an image as 4-element array */
+PHP_FUNCTION(getimagesize)
+{
+       zval **arg1, **info = NULL;
+       php_stream *stream = NULL;
+
+       switch(ZEND_NUM_ARGS()) {
+
+       case 1:
+               if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
+                       RETVAL_FALSE;
+                       WRONG_PARAM_COUNT;
+               }
+               convert_to_string_ex(arg1);
+               break;
+
+       case 2:
+               if (zend_get_parameters_ex(2, &arg1, &info) == FAILURE) {
+                       RETVAL_FALSE;
+                       WRONG_PARAM_COUNT;
+               }
+               zval_dtor(*info);
+
+               array_init(*info);
+
+               convert_to_string_ex(arg1);
+               break;
+
+       default:
+               RETVAL_FALSE;
+               WRONG_PARAM_COUNT;
+       }
+
+       stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
+
+       if (!stream) {
+               RETURN_FALSE;
+       }
+
+       php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+
+       php_stream_close(stream);
+}
+/* }}} */
+
+/* {{{ proto array getimagesizefromstring(string data [, array info])
+   Get the size of an image as 4-element array */
+PHP_FUNCTION(getimagesizefromstring)
+{
+       char *data = NULL;
+       long data_len = 0;
+       zval **info = NULL;
+       php_stream *stream = NULL;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Z", &data, &data_len, &info) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       if (info != NULL) {
+               zval_dtor(*info);
+               array_init(*info);
+       }
+
+       stream = php_stream_memory_open(TEMP_STREAM_READONLY, data, data_len);
+
+       if (!stream) {
+               RETURN_FALSE;
+       }
+
+       php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+
+       php_stream_close(stream);
+}
+
 /*
  * Local variables:
  * tab-width: 4
