Re: cvs: php4 /ext/standard basic_functions.c image.c php_image.h
| From: | Andi Gutmans | Date: | Sat, 22 Jun 2002 19:51:54 +0000 |
| Subject: | Re: cvs: php4 /ext/standard basic_functions.c image.c php_image.h | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-12450@lists.php.net to get a copy of this message | ||
As this is a new function can we please make its name compliant with out naming standard?
image_type_to_mime_type()
Andi
At 06:14 PM 6/22/2002 +0000, Marcus Börger wrote:
helly Sat Jun 22 14:14:39 2002 EDTModified files:/php4/ext/standard basic_functions.c image.c php_image.hLog: @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. Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.479 php4/ext/standard/basic_functions.c:1.480 --- php4/ext/standard/basic_functions.c:1.479 Wed Jun 12 13:25:48 2002 +++ php4/ext/standard/basic_functions.c Sat Jun 22 14:14:39 2002 @@ -17,7 +17,7 @@+----------------------------------------------------------------------+*/ -/* $Id: basic_functions.c,v 1.479 2002/06/12 17:25:48 sniper Exp $ */ +/* $Id: basic_functions.c,v 1.480 2002/06/22 18:14:39 helly Exp $ */ #include "php.h" #include "php_streams.h" @@ -281,6 +281,7 @@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: php4/ext/standard/image.c diff -u php4/ext/standard/image.c:1.57 php4/ext/standard/image.c:1.58--- php4/ext/standard/image.c:1.57 Sat Jun 22 13:09:28 2002+++ php4/ext/standard/image.c Sat Jun 22 14:14:39 2002 @@ -16,7 +16,7 @@| Marcus Boerger <helly@php.net> | +----------------------------------------------------------------------+*/ -/* $Id: image.c,v 1.57 2002/06/22 17:09:28 helly Exp $ */ +/* $Id: image.c,v 1.58 2002/06/22 18:14:39 helly Exp $ */ /* * Based on Daniel Schmitt's imageinfo.c which carried the following * Copyright notice. @@ -65,7 +65,7 @@ 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 @@ } /* }}} */ +/* {{{ 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_imagetypedetect filetype from first bytes */PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC) @@ -824,6 +868,7 @@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: php4/ext/standard/php_image.h diff -u php4/ext/standard/php_image.h:1.14 php4/ext/standard/php_image.h:1.15 --- php4/ext/standard/php_image.h:1.14 Thu May 23 17:48:27 2002+++ php4/ext/standard/php_image.h Sat Jun 22 14:14:39 2002@@ -17,13 +17,15 @@+----------------------------------------------------------------------+*/ -/* $Id: php_image.h,v 1.14 2002/05/23 21:48:27 derick Exp $ */ +/* $Id: php_image.h,v 1.15 2002/06/22 18:14:39 helly Exp $ */ #ifndef PHP_IMAGE_H #define PHP_IMAGE_H PHP_FUNCTION(getimagesize); +PHP_FUNCTION(imagetype2mimetype); + /* {{{ enum image_filetypeThis enum is used to have ext/standard/image.c and ext/exif/exif.c use the same constants for file types.@@ -47,5 +49,7 @@ /* }}} */ PHPAPI int php_getimagetype(php_stream *stream, char *filetype TSRMLS_DC); + +PHPAPI const char * php_imagetype2mimetype(int image_type); #endif /* PHP_IMAGE_H */ -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php