Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_get_image_mime ›

Seit4.7.1
Veraltetn/v
wp_get_image_mime ( $file )
Parameter:
  • (string) $file Full path to the file.
    Erforderlich: Ja
Gibt zurück:
  • (string|false) The actual mime type or false if the type cannot be determined.
Definiert in:
Codex:

Returns the real mime type of an image file.

This depends on exif_imagetype() or getimagesize() to determine real mime types.



Quellcode

function wp_get_image_mime( $file ) {
	/*
	 * Use exif_imagetype() to check the mimetype if available or fall back to
	 * getimagesize() if exif isn't avaialbe. If either function throws an Exception
	 * we assume the file could not be validated.
	 */
	try {
		if ( is_callable( 'exif_imagetype' ) ) {
			$mime = image_type_to_mime_type( exif_imagetype( $file ) );
		} elseif ( function_exists( 'getimagesize' ) ) {
			$imagesize = getimagesize( $file );
			$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
		} else {
			$mime = false;
		}
	} catch ( Exception $e ) {
		$mime = false;
	}

	return $mime;
}