PHP | image_type_to_mime_type() Function

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
echo image_type_to_mime_type(IMAGETYPE_PNG);
?>

chevron_right


Output:

image/png

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
echo image_type_to_mime_type(IMAGETYPE_JPEG);
?>

chevron_right


Output:

image/jpeg

Reference: https://www.php.net/manual/en/function.image-type-to-mime-type.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.