Added image_type_to_extension() function.

This commit is contained in:
Ilia Alshanetsky 2003-11-27 22:03:35 +00:00
parent 1586f714fe
commit e898ae955e
3 changed files with 45 additions and 0 deletions

1
NEWS
View file

@ -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)

View file

@ -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)

View file

@ -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