Title: wp_get_webp_info
Published: July 20, 2021
Last modified: May 20, 2026

---

# wp_get_webp_info( string $filename ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#wp--skip-link--target)

Extracts meta information about a WebP file: width, height, and type.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#parameters)󠁿

 `$filename`stringrequired

Path to a WebP file.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#return)󠁿

 array An array of WebP image information.

 * `width` int|false
 * Image width on success, false on failure.
 * `height` int|false
 * Image height on success, false on failure.
 * `type` string|false
 * The WebP type: one of `'lossy'`, `'lossless'` or `'animated-alpha'`.
    False on
   failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#source)󠁿

    ```php
    function wp_get_webp_info( $filename ) {
    	$width  = false;
    	$height = false;
    	$type   = false;

    	if ( 'image/webp' !== wp_get_image_mime( $filename ) ) {
    		return compact( 'width', 'height', 'type' );
    	}

    	$magic = file_get_contents( $filename, false, null, 0, 40 );

    	if ( false === $magic ) {
    		return compact( 'width', 'height', 'type' );
    	}

    	// Make sure we got enough bytes.
    	if ( strlen( $magic ) < 40 ) {
    		return compact( 'width', 'height', 'type' );
    	}

    	/*
    	 * The headers are a little different for each of the three formats.
    	 * Header values based on WebP docs, see https://developers.google.com/speed/webp/docs/riff_container.
    	 */
    	switch ( substr( $magic, 12, 4 ) ) {
    		// Lossy WebP.
    		case 'VP8 ':
    			$parts  = unpack( 'v2', substr( $magic, 26, 4 ) );
    			$width  = (int) ( $parts[1] & 0x3FFF );
    			$height = (int) ( $parts[2] & 0x3FFF );
    			$type   = 'lossy';
    			break;
    		// Lossless WebP.
    		case 'VP8L':
    			$parts  = unpack( 'C4', substr( $magic, 21, 4 ) );
    			$width  = (int) ( $parts[1] | ( ( $parts[2] & 0x3F ) << 8 ) ) + 1;
    			$height = (int) ( ( ( $parts[2] & 0xC0 ) >> 6 ) | ( $parts[3] << 2 ) | ( ( $parts[4] & 0x03 ) << 10 ) ) + 1;
    			$type   = 'lossless';
    			break;
    		// Animated/alpha WebP.
    		case 'VP8X':
    			// Pad 24-bit int.
    			$width = unpack( 'V', substr( $magic, 24, 3 ) . "\x00" );
    			$width = (int) ( $width[1] & 0xFFFFFF ) + 1;
    			// Pad 24-bit int.
    			$height = unpack( 'V', substr( $magic, 27, 3 ) . "\x00" );
    			$height = (int) ( $height[1] & 0xFFFFFF ) + 1;
    			$type   = 'animated-alpha';
    			break;
    	}

    	return compact( 'width', 'height', 'type' );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/media.php#L5902)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/media.php#L5902-L5954)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_get_image_mime()](https://developer.wordpress.org/reference/functions/wp_get_image_mime/)`wp-includes/functions.php` |

Returns the real mime type of an image file.

  |

| Used by | Description | 
| [WP_Image_Editor_GD::set_quality()](https://developer.wordpress.org/reference/classes/wp_image_editor_gd/set_quality/)`wp-includes/class-wp-image-editor-gd.php` |

Sets Image Compression quality on a 1-100% scale. Handles WebP lossless images.

  | 
| [wp_getimagesize()](https://developer.wordpress.org/reference/functions/wp_getimagesize/)`wp-includes/media.php` |

Allows PHP’s getimagesize() to be debuggable when necessary.

  | 
| [WP_Image_Editor_Imagick::set_quality()](https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/set_quality/)`wp-includes/class-wp-image-editor-imagick.php` |

Sets Image Compression quality on a 1-100% scale.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_get_webp_info/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_get_webp_info%2F)
before being able to contribute a note or feedback.