iliaa           Thu Nov 27 17:03:37 2003 EDT

  Modified files:              
    /php-src/ext/standard       image.c php_image.h 
    /php-src    NEWS 
  Log:
  Added image_type_to_extension() function.
  
  
Index: php-src/ext/standard/image.c
diff -u php-src/ext/standard/image.c:1.95 php-src/ext/standard/image.c:1.96
--- php-src/ext/standard/image.c:1.95   Wed Nov 12 17:51:22 2003
+++ php-src/ext/standard/image.c        Thu Nov 27 17:03:34 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: image.c,v 1.95 2003/11/12 22:51:22 helly Exp $ */
+/* $Id: image.c,v 1.96 2003/11/27 22:03:34 iliaa Exp $ */
 
 #include "php.h"
 #include <stdio.h>
@@ -1089,6 +1089,49 @@
 }
 /* }}} */
 
+/* {{{ 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: php-src/ext/standard/php_image.h
diff -u php-src/ext/standard/php_image.h:1.26 php-src/ext/standard/php_image.h:1.27
--- php-src/ext/standard/php_image.h:1.26       Tue Sep  9 15:25:55 2003
+++ php-src/ext/standard/php_image.h    Thu Nov 27 17:03:34 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_image.h,v 1.26 2003/09/09 19:25:55 sniper Exp $ */
+/* $Id: php_image.h,v 1.27 2003/11/27 22:03:34 iliaa Exp $ */
 
 #ifndef PHP_IMAGE_H
 #define 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
Index: php-src/NEWS
diff -u php-src/NEWS:1.1503 php-src/NEWS:1.1504
--- php-src/NEWS:1.1503 Mon Nov 24 14:01:45 2003
+++ php-src/NEWS        Thu Nov 27 17:03:35 2003
@@ -7,6 +7,7 @@
   . 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)



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to