List Info

Thread: note 69990 added to function.image-type-to-extension




note 69990 added to function.image-type-to-extension
user name
2006-09-28 23:40:42
2006-09-29 Author: Ian Paul Short (chukdocs at hotmail dot
com)

For reasons I have yet to determine the function
“image_type_to_extension” is not available to both PHP
5.1.4 on my local host running under Windows XP or on my
remote host running under Linux. Has anyone else had this
problem? If so kindly post your findings here please.

In the meantime I needed a workaround and with many thanks
to the previous contributors on this page - I took bits and
pieces developed the following function to emulate the
function image_type_to_extension:

	if(!function_exists('image_type_to_extension')){	###
Include this for graceful tranisition to using 
														### PHP's equivalent function when it's
available in the box
		
		function image_type_to_extension($image_type,
$include_dot){
			
			// Assign definitions and intialise variables
			define ("INVALID_IMAGETYPE", '');			// Empty
string 			
			$extension = INVALID_IMAGETYPE; 			// Return this (empty
string) if "$image_type or $include_dot" do not
contain legal values   

			
			if((is_int($image_type)) AND (is_bool($include_dot)) AND
(IMAGETYPE_GIF <= $image_type) AND (IMAGETYPE_XBM >=
$image_type)){ // Check input data are legal 
			
				$image_type_extension = array (			### These integer
values correspond to the the respective IMAGETYPE constants
    				IMAGETYPE_GIF 		=> 'gif',		###  1 = GIF
					IMAGETYPE_JPEG 		=> 'jpg',		###  2 = JPG
					IMAGETYPE_PNG 		=> 'png',		###  3 = PNG
					IMAGETYPE_SWF 		=> 'swf',		###  4 = SWF
					IMAGETYPE_PSD 		=> 'psd',		###  5 = PSD
					IMAGETYPE_BMP 		=> 'bmp',		###  6 = BMP	
					IMAGETYPE_TIFF_II 	=> 'tiff',		###  7 = TIFF 	(intel
byte order)
					IMAGETYPE_TIFF_MM 	=> 'tiff',		###  8 = TIFF
	(motorola byte order)
					IMAGETYPE_JPC 		=> 'jpc',		###  9 = JPC
					IMAGETYPE_JP2 		=> 'jp2',		### 10 = JP2
					IMAGETYPE_JPX 		=> 'jpf',		### 11 = JPX 	Yes! jpf
extension is correct for JPX image type
					IMAGETYPE_JB2 		=> 'jb2',		### 12 = JB2
					IMAGETYPE_SWC 		=> 'swc',		### 13 = SWC
					IMAGETYPE_IFF 		=> 'aiff',		### 14 = IFF
					IMAGETYPE_WBMP 		=> 'wbmp',		### 15 = WBMP
					IMAGETYPE_XBM 		=> 'xbm'		### 16 = XBM
				);
							
				$extension = $image_type_extension[$image_type]; // Get
extension by using array as a look up table using
$image_type as key
				
				if($include_dot != false) $extension = '.' . $extension;
// If $include_dot is true prefix a dot to extension
   			}

### Limitation - No user friendly error handler   			
/*			
			else
   			{
   				### Put your error handler here
   			}					
*/		
		return $extension;
		}
	}
----
Server IP: 83.138.144.80
Probable Submitter: 86.142.241.158
----
Manual Page -- http://www.php.net/manual/en/function.image-typ
e-to-extension.php
Edit        -- https://master
.php.net/note/edit/69990
Del: integrated  -- h
ttps://master.php.net/note/delete/69990/integrated
Del: useless     -- http
s://master.php.net/note/delete/69990/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/69990/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/69990/spam
Del: non-english -- 
https://master.php.net/note/delete/69990/non-english
Del: in docs     -- http
s://master.php.net/note/delete/69990/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/69990
Reject      -- https://mast
er.php.net/note/reject/69990
Search      -- https://
master.php.net/manage/user-notes.php

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

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )