From: Ilia Alshanetsky Date: Thu, 27 Nov 2003 22:03:35 +0000 (+0000) Subject: Added image_type_to_extension() function. X-Git-Tag: php-5.0.0b3RC1~566 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e898ae955e957fcda3635055f55aa841c4446cc1;p=php Added image_type_to_extension() function. --- diff --git a/NEWS b/NEWS index edcf4aa017..99533afe9c 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ PHP NEWS . headers_list(). (Sara) . php_strip_whitespace(). strip whitespace & comments from a script. (Ilia) . php_check_syntax(). check php script for parse errors. (Ilia) + . image_type_to_extension(). return extension based on image type. (Ilia) - Fixed __autoload() to preserve case of the passed class name. (Andi) - Fixed bug #26072 (--disable-libxml does not work). (Jani) - Fixed bug #26083 (Non-working write support in ext/dom). (Ilia) diff --git a/ext/standard/image.c b/ext/standard/image.c index 9cd1124ac4..636eaceb3a 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1089,6 +1089,49 @@ PHP_FUNCTION(image_type_to_mime_type) } /* }}} */ +/* {{{ proto string image_type_to_extension(int imagetype [, bool include_dot]) + Get file extension for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype */ +PHP_FUNCTION(image_type_to_extension) +{ + long image_type; + zend_bool inc_dot=1; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &image_type, &inc_dot) == FAILURE) { + RETURN_FALSE; + } + + switch (image_type) { + case IMAGE_FILETYPE_GIF: + RETURN_STRING(".gif" + !inc_dot, 1); + case IMAGE_FILETYPE_JPEG: + RETURN_STRING(".jpeg" + !inc_dot, 1); + case IMAGE_FILETYPE_PNG: + RETURN_STRING(".png" + !inc_dot, 1); + case IMAGE_FILETYPE_SWF: + case IMAGE_FILETYPE_SWC: + RETURN_STRING(".swf" + !inc_dot, 1); + case IMAGE_FILETYPE_PSD: + RETURN_STRING(".psd" + !inc_dot, 1); + case IMAGE_FILETYPE_BMP: + case IMAGE_FILETYPE_WBMP: + RETURN_STRING(".bmp" + !inc_dot, 1); + case IMAGE_FILETYPE_TIFF_II: + case IMAGE_FILETYPE_TIFF_MM: + RETURN_STRING(".tiff" + !inc_dot, 1); + case IMAGE_FILETYPE_IFF: + RETURN_STRING(".iff" + !inc_dot, 1); + case IMAGE_FILETYPE_JPC: + RETURN_STRING(".jpc" + !inc_dot, 1); + case IMAGE_FILETYPE_JP2: + RETURN_STRING(".jp2" + !inc_dot, 1); + case IMAGE_FILETYPE_XBM: + RETURN_STRING(".xbm" + !inc_dot, 1); + } + + RETURN_FALSE; +} +/* }}} */ + /* {{{ php_imagetype detect filetype from first bytes */ PHPAPI int php_getimagetype(php_stream * stream, char *filetype TSRMLS_DC) diff --git a/ext/standard/php_image.h b/ext/standard/php_image.h index 1d3e9038dc..dc3bc420e9 100644 --- a/ext/standard/php_image.h +++ b/ext/standard/php_image.h @@ -25,6 +25,7 @@ PHP_FUNCTION(getimagesize); PHP_FUNCTION(image_type_to_mime_type); +PHP_FUNCTION(image_type_to_extension); /* {{{ enum image_filetype This enum is used to have ext/standard/image.c and ext/exif/exif.c use