PHP | image_type_to_mime_type() Function
Last Updated :
20 Nov, 2019
The image_type_to_mime_type() function is an inbuilt function in PHP which is used to get the MimeType for an imagetype returned by other different functions like getimagesize(), exif_read_data(), exif_thumbnail(), exif_imagetype() etc.
The MIME stands for Multi-purpose Internet Mail Extensions. MIME types form is a standard way of classifying file types on the Internet. Internet programs such as Web servers and browsers all have a list of MIME types, so that they can transfer files of the same type in the same way, no matter what operating system they are working.
Syntax:
string image_type_to_mime_type( int $imagetype )
Parameters: This function accepts single parameter $imagetype which holds an integer value of IMAGETYPE_XXX constants such as IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG etc.
Return values: This function returns a string of Mime Type for the given IMAGETYPE constant.
Below is an exhaustive list of all return values.
imagetype |
Return value |
IMAGETYPE_GIF |
image/gif |
IMAGETYPE_JPEG |
image/jpeg |
IMAGETYPE_PNG |
image/png |
IMAGETYPE_SWF |
application/x-shockwave-flash |
IMAGETYPE_PSD |
image/psd |
IMAGETYPE_BMP |
image/bmp |
IMAGETYPE_TIFF_II (intel byte order) |
image/tiff |
IMAGETYPE_TIFF_MM (motorola byte order) |
image/tiff |
IMAGETYPE_JPC |
application/octet-stream |
IMAGETYPE_JP2 |
image/jp2 |
IMAGETYPE_JPX |
application/octet-stream |
IMAGETYPE_JB2 |
application/octet-stream |
IMAGETYPE_SWC |
application/x-shockwave-flash |
IMAGETYPE_IFF |
image/iff |
IMAGETYPE_WBMP |
image/vnd.wap.wbmp |
IMAGETYPE_XBM |
image/xbm |
IMAGETYPE_ICO |
image/vnd.microsoft.icon |
IMAGETYPE_WEBP |
image/webp |
Below programs illustrate the image_type_to_mime_type() function in PHP:
Program 1:
<?php
echo image_type_to_mime_type(IMAGETYPE_PNG);
?>
|
Output:
image/png
Program 2:
<?php
echo image_type_to_mime_type(IMAGETYPE_JPEG);
?>
|
Output:
image/jpeg
Reference: https://www.php.net/manual/en/function.image-type-to-mime-type.php
Share your thoughts in the comments
Please Login to comment...