exif_imagetype example


function wp_get_image_mime( $file ) {
    /* * Use exif_imagetype() to check the mimetype if available or fall back to * getimagesize() if exif isn't available. If either function throws an Exception * we assume the file could not be validated. */
    try {
        if ( is_callable( 'exif_imagetype' ) ) {
            $imagetype = exif_imagetype( $file );
            $mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
        } elseif ( function_exists( 'getimagesize' ) ) {
            // Don't silence errors when in debug mode, unless running unit tests.             if ( defined( 'WP_DEBUG' ) && WP_DEBUG
                && ! defined( 'WP_RUN_CORE_TESTS' )
            ) {
                // Not using wp_getimagesize() here to avoid an infinite loop.                 $imagesize = getimagesize( $file );
            } else {
                // phpcs:ignore WordPress.PHP.NoSilencedErrors                 $imagesize = @getimagesize( $file );
            }
Home | Imprint | This part of the site doesn't use cookies.