summaryrefslogtreecommitdiff
path: root/ext/standard/image.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/image.c')
-rw-r--r--ext/standard/image.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/ext/standard/image.c b/ext/standard/image.c
index 201b5f5f7..9ca873716 100644
--- a/ext/standard/image.c
+++ b/ext/standard/image.c
@@ -1289,26 +1289,11 @@ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
}
/* }}} */
-/* {{{ 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;
@@ -1374,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);
@@ -1398,6 +1381,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:
* tab-width: 4