]> granicus.if.org Git - php/commitdiff
Added image_type_to_extension() function.
authorIlia Alshanetsky <iliaa@php.net>
Thu, 27 Nov 2003 22:03:35 +0000 (22:03 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 27 Nov 2003 22:03:35 +0000 (22:03 +0000)
NEWS
ext/standard/image.c
ext/standard/php_image.h

diff --git a/NEWS b/NEWS
index edcf4aa01706c3d83b74ea08dfae8d3f70c1ea83..99533afe9c65682aa2e7927665901a2314c1fe22 100644 (file)
--- 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)
index 9cd1124ac47d7889905948953ceabdcff650fe8d..636eaceb3a3d645f11979564bc291b3288e0054c 100644 (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)
index 1d3e9038dc1f17035c169c2c2b97759e890fc866..dc3bc420e9e1e0677650c86ed84bc8da5f890909 100644 (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