summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2002-06-22 18:14:39 +0000
committerMarcus Boerger <helly@php.net>2002-06-22 18:14:39 +0000
commitc8f1529d08976be948356622a2b27cddee023d51 (patch)
tree6fc3ddb8e385611884b5234ff7ceec2ef8edf1ef /ext/standard
parentd4b1909afe800d6368de2a11225bb39682d54784 (diff)
downloadphp-git-c8f1529d08976be948356622a2b27cddee023d51.tar.gz
@GetImageSize now returns additional index 'MimeType' and new function
@imagetype2mimetype to convert php imagetypes to mime-types. (Marcus) #the reason why i export php_imagetype2mimetype is that i use that for #exif, too. Followup example will explain why.
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/basic_functions.c1
-rw-r--r--ext/standard/image.c47
-rw-r--r--ext/standard/php_image.h4
3 files changed, 51 insertions, 1 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index da61cf0b39..89c1cacd01 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -281,6 +281,7 @@ function_entry basic_functions[] = {
PHP_FE(iptcparse, NULL)
PHP_FE(iptcembed, NULL)
PHP_FE(getimagesize, second_args_force_ref)
+ PHP_FE(imagetype2mimetype, NULL)
PHP_FE(phpinfo, NULL)
PHP_FE(phpversion, NULL)
diff --git a/ext/standard/image.c b/ext/standard/image.c
index 44a462bceb..3e7ef909a8 100644
--- a/ext/standard/image.c
+++ b/ext/standard/image.c
@@ -65,7 +65,7 @@ PHPAPI const char php_sig_png[8] = {(char) 0x89, (char) 0x50, (char) 0x4e, (char
PHPAPI const char php_sig_tif_ii[4] = {'I','I', (char)0x2A, (char)0x00};
PHPAPI const char php_sig_tif_mm[4] = {'M','M', (char)0x00, (char)0x2A};
PHPAPI const char php_sig_jpc[3] = {(char)0xFF, (char)0x4F, (char)0xff};
-
+/* REMEMBER TO ADD MIME-TYPE TO FUNCTION php_imagetype2mimetype */
/* return info as a struct, to make expansion easier */
@@ -668,6 +668,50 @@ static struct gfxinfo *php_handle_tiff (php_stream * stream, pval *info, int mot
}
/* }}} */
+/* {{{ php_imagetype2mimetype
+ * Convert internal image_type to mime type */
+PHPAPI const char * php_imagetype2mimetype(int image_type)
+{
+ switch( image_type) {
+ case IMAGE_FILETYPE_GIF:
+ return "image/gif";
+ case IMAGE_FILETYPE_JPEG:
+ case IMAGE_FILETYPE_JPC:
+ return "image/jpeg";
+ case IMAGE_FILETYPE_PNG:
+ return "image/png";
+ case IMAGE_FILETYPE_SWF:
+ case IMAGE_FILETYPE_SWC:
+ return "application/x-shockwave-flash";
+ case IMAGE_FILETYPE_PSD:
+ return "image/psd";
+ case IMAGE_FILETYPE_BMP:
+ return "image/bmp";
+ case IMAGE_FILETYPE_TIFF_II:
+ case IMAGE_FILETYPE_TIFF_MM:
+ return "image/tiff";
+ default:
+ case IMAGE_FILETYPE_UNKNOWN:
+ return "application/octet-stream"; /* suppose binary format */
+ }
+}
+/* }}} */
+
+/* {{{ proto array imagetype2mimetype(int imagetype)
+ Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */
+PHP_FUNCTION(imagetype2mimetype)
+{
+ zval **p_image_type;
+ int arg_c = ZEND_NUM_ARGS();
+
+ if ((arg_c!=1) || zend_get_parameters_ex(arg_c, &p_image_type) == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ zval_dtor(*p_image_type);
+ ZVAL_STRING(return_value, (char*)php_imagetype2mimetype(Z_LVAL_PP(p_image_type)), 1);
+}
+/* }}} */
+
/* {{{ php_imagetype
detect filetype from first bytes */
PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC)
@@ -824,6 +868,7 @@ PHP_FUNCTION(getimagesize)
if (result->channels != 0) {
add_assoc_long(return_value, "channels", result->channels);
}
+ add_assoc_string(return_value, "mime", (char*)php_imagetype2mimetype(itype), 1);
efree(result);
} else {
RETURN_FALSE;
diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h
index a33c60759f..6ca658b278 100644
--- a/ext/standard/php_image.h
+++ b/ext/standard/php_image.h
@@ -24,6 +24,8 @@
PHP_FUNCTION(getimagesize);
+PHP_FUNCTION(imagetype2mimetype);
+
/* {{{ enum image_filetype
This enum is used to have ext/standard/image.c and ext/exif/exif.c use
the same constants for file types.
@@ -48,4 +50,6 @@ typedef enum
PHPAPI int php_getimagetype(php_stream *stream, char *filetype TSRMLS_DC);
+PHPAPI const char * php_imagetype2mimetype(int image_type);
+
#endif /* PHP_IMAGE_H */