image_type_to_extension 


php apg

GETS the file extension for image type.


This function does not require the GD image library.

Included in this section for being in common use.





  MIME-Type   

A media type (formerly known as MIME-type) is a two-part identifier for file formats and format contents transmitted on the Internet.

The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication of these classifications.

Media types were originally defined in Request for Comments RFC 2045 (MIME) Part One: Format of Internet Message Bodies (Nov 1996) in November 1996 as a part of MIME (Multipurpose Internet Mail Extensions) specification, for denoting type of email message content and attachments; hence the original name, MIME-type.

Media types are also used by other internet protocols such as HTTP and document file formats such as HTML, for similar purposes.

From Wikipedia, the free encyclopedia.



<?php

string
|false image_type_to_extension int $image_type
                                                          
bool $include_dot TRUE )

where,

$image_type One of the IMAGETYPE_ constants
                       
SEE the below TABLE )
                     
$include_dot To control if to prepend 
                                      a dot to the extension 
or not 

?>

  $imagetype   

The IMAGETYPE_XXX constants.
CONSTANT VALUE MEANING
IMAGETYPE_GIF 1 image/gif
IMAGETYPE_JPEG 2 image/jpeg
IMAGETYPE_PNG 3 image/png
IMAGETYPE_SWF 4 application/x-shockwave-flash
IMAGETYPE_PSD 5 image/psd
IMAGETYPE_BMP 6 image/bmp
IMAGETYPE_TIFF_II
(Intel byte order)
7 image/tiff
IMAGETYPE_TIFF_MM
(Motorola byte order)
8 image/tiff
IMAGETYPE_JPC 9 application/octet-stream
IMAGETYPE_JP2 10 image/jp2
IMAGETYPE_JPX 11 application/octet-stream
IMAGETYPE_JB2 12 application/octet-stream
IMAGETYPE_SWC 13 application/x-shockwave-flash
IMAGETYPE_IFF 14 image/iff
IMAGETYPE_WBMP 15 image/vnd.wap.wbmp
IMAGETYPE_XBM 16 image/xbm
IMAGETYPE_ICO 17 image/vnd.microsoft.icon
IMAGETYPE_WEBP 18 image/webp
IMAGETYPE_AVIF
(Since PHP 8.1.0)
19 image/avif
ed48


  $include_dot   


VALUE MEANING DEFAULT
TRUE The dot will be included TRUE
FALSE The dot will not be included
ed48


  1 EXERCISE   

<?php

if(PHP_VERSION_ID 80100)
{

for (
$x 1$x <= 18$x++)
{
    echo 
$x ' = ' image_type_to_mime_type($x) . ' => ( ' 
                          
image_type_to_extension($x) . ' )<br>';
}
}
else
{
    for (
$x 1$x <= 19$x++)
{
    echo 
$x ' = ' image_type_to_mime_type($x) . ' => ( ' 
                          
image_type_to_extension($x) . ' )<br>';
}
}

?>

 RESULT   

1 = image/gif => ( .gif )
2 = image/jpeg => ( .jpeg )
3 = image/png => ( .png )
4 = application/x-shockwave-flash => ( .swf )
5 = image/psd => ( .psd )
6 = image/bmp => ( .bmp )
7 = image/tiff => ( .tiff )
8 = image/tiff => ( .tiff )
9 = application/octet-stream => ( .jpc )
10 = image/jp2 => ( .jp2 )
11 = application/octet-stream => ( .jpx )
12 = application/octet-stream => ( .jb2 )
13 = application/x-shockwave-flash => ( .swf )
14 = image/iff => ( .iff )
15 = image/vnd.wap.wbmp => ( .bmp )
16 = image/xbm => ( .xbm )
17 = image/vnd.microsoft.icon => ( .ico )
18 = image/webp => ( .webp )
19 = image/avif => ( .aviv )
         (Since PHP 8.1.0)

Extension with the prepended dot.

  2 EXERCISE   

<?php

if(PHP_VERSION_ID 80100)
{

for (
$x 1$x <= 18$x++)
{
    echo 
$x ' = ' image_type_to_mime_type($x) . ' => ( ' 
                          
image_type_to_extension($xfalse) . ' )<br>';
}
}
else
{
    for (
$x 1$x <= 19$x++)
{
    echo 
$x ' = ' image_type_to_mime_type($x) . ' => ( ' 
                          
image_type_to_extension($xfalse) . ' )<br>';
}
}

?>

 RESULT   

1 = image/gif => ( gif )
2 = image/jpeg => ( jpeg )
3 = image/png => ( png )
4 = application/x-shockwave-flash => ( .swf )
5 = image/psd => ( psd )
6 = image/bmp => ( bmp )
7 = image/tiff => ( tiff )
8 = image/tiff => ( tiff )
9 = application/octet-stream => ( .jpc )
10 = image/jp2 => ( jp2 )
11 = application/octet-stream => ( jpx )
12 = application/octet-stream => ( jb2 )
13 = application/x-shockwave-flash => ( swf )
14 = image/iff => ( iff )
15 = image/vnd.wap.wbmp => ( bmp )
16 = image/xbm => ( xbm )
17 = image/vnd.microsoft.icon => ( ico )
18 = image/webp => ( webp )
19 = image/avif => ( aviv )
         (Since PHP 8.1.0)

Extension without the prepended dot.