summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Joye <pajoye@php.net>2010-05-05 13:37:40 +0000
committerPierre Joye <pajoye@php.net>2010-05-05 13:37:40 +0000
commitb9730786a7018c31b1b31e12e28fc617c00564fe (patch)
tree64243c46cb86b8b708b4831255e50eeea464cb13
parent8a0450698d591b3af641c9719f552e08cc3af7be (diff)
downloadphp-git-b9730786a7018c31b1b31e12e28fc617c00564fe.tar.gz
- #51063, implement getimagesizefromstring
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/image.c69
-rw-r--r--ext/standard/php_image.h1
3 files changed, 53 insertions, 18 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 26c6d5aed0..88ea346a7e 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -2690,6 +2690,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */
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)
diff --git a/ext/standard/image.c b/ext/standard/image.c
index 4ce895438e..a622716600 100644
--- a/ext/standard/image.c
+++ b/ext/standard/image.c
@@ -1294,26 +1294,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();
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, NULL);
if (!stream) {
RETURN_FALSE;
@@ -1379,8 +1364,6 @@ PHP_FUNCTION(getimagesize)
break;
}
- php_stream_close(stream);
-
if (result) {
array_init(return_value);
add_index_long(return_value, 0, result->width);
@@ -1403,6 +1386,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
diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h
index 5a252bbf9f..706dacd519 100644
--- a/ext/standard/php_image.h
+++ b/ext/standard/php_image.h
@@ -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);