]> granicus.if.org Git - php/commitdiff
@GetImageSize now returns additional index 'MimeType' and new function
authorMarcus Boerger <helly@php.net>
Sat, 22 Jun 2002 18:14:39 +0000 (18:14 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 22 Jun 2002 18:14:39 +0000 (18:14 +0000)
@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.

ext/standard/basic_functions.c
ext/standard/image.c
ext/standard/php_image.h

index da61cf0b394180863b967ebb9315c313a390713f..89c1cacd01a381820b8dd5cbfe87272ecfcf0e9f 100644 (file)
@@ -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)
index 44a462bceb72b0fa154126078512ba06bd6daa93..3e7ef909a886aedc60670d50ccf6846fbaed10d0 100644 (file)
@@ -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;
index a33c60759fcc9a633640ccfca6f778e21ea2d33c..6ca658b2788cc6d6e12934a0a1fa45c8ce5dc37e 100644 (file)
@@ -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 */