wp_get_image_mime()
Gets the real MIME type of an image file.
We can't trust to the image type in the image name, for example png image can be called image.jpg.
PHP functions are used to accurately determine mime:
- exif_imagetype() - determine type of an image.
- image_type_to_mime_type() - get Mime-Type for image-type returned by getimagesize(), exif_read_data(), exif_thumbnail(), exif_imagetype().
- getimagesize() - get the size of an image.
Used By: wp_check_filetype_and_ext()
1 time — 0.135771 sec (extremely slow) | 50000 times — 176.48 sec (extremely slow) | PHP 7.1.11, WP 4.9.4
No Hooks.
Return
String|false
. The actual mime type or false if the type cannot be determined.
Usage
wp_get_image_mime( $file );
- $file(string) (required)
- Full path to the file.
Examples
#1 Get the mime type of the image in the template files (screenshot of the theme)
$screenshot_path = get_template_directory() . '/screenshot.png'; echo wp_get_image_mime( $screenshot_path ); //> image/png
Changelog
Since 4.7.1 | Introduced. |
Since 5.8.0 | Added support for WebP images. |