note 69990 deleted from function.image-type-to-extension by sobak
| From: | sobak@php.net | Date: | Thu, 01 Dec 2016 13:08:55 +0000 |
| Subject: | note 69990 deleted from function.image-type-to-extension by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207844@lists.php.net to get a copy of this message | ||
Note Submitter: Ian Paul Short
----
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;
}
}