Title: wp_getimagesize
Published: March 9, 2021
Last modified: February 24, 2026

---

# wp_getimagesize( string $filename, array $image_info = null ): array|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#user-contributed-notes)

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

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

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

 `$filename`stringrequired

The file path.

`$image_info`arrayoptional

Extended image information (passed by reference).

Default:`null`

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

 array|false Array of image information or false on failure.

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

    ```php
    function wp_getimagesize( $filename, ?array &$image_info = null ) {
    	// Don't silence errors when in debug mode, unless running unit tests.
    	if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! defined( 'WP_RUN_CORE_TESTS' ) ) {
    		if ( 2 === func_num_args() ) {
    			$info = getimagesize( $filename, $image_info );
    		} else {
    			$info = getimagesize( $filename );
    		}
    	} else {
    		/*
    		 * Silencing notice and warning is intentional.
    		 *
    		 * getimagesize() has a tendency to generate errors, such as
    		 * "corrupt JPEG data: 7191 extraneous bytes before marker",
    		 * even when it's able to provide image size information.
    		 *
    		 * See https://core.trac.wordpress.org/ticket/42480
    		 */
    		if ( 2 === func_num_args() ) {
    			$info = @getimagesize( $filename, $image_info );
    		} else {
    			$info = @getimagesize( $filename );
    		}
    	}

    	if (
    		! empty( $info ) &&
    		// Some PHP versions return 0x0 sizes from `getimagesize` for unrecognized image formats, including AVIFs.
    		! ( empty( $info[0] ) && empty( $info[1] ) )
    	) {
    		return $info;
    	}

    	$image_mime_type = wp_get_image_mime( $filename );

    	// Not an image?
    	if ( false === $image_mime_type ) {
    		return false;
    	}

    	/*
    	 * For PHP versions that don't support WebP images,
    	 * extract the image size info from the file headers.
    	 */
    	if ( 'image/webp' === $image_mime_type ) {
    		$webp_info = wp_get_webp_info( $filename );
    		$width     = $webp_info['width'];
    		$height    = $webp_info['height'];

    		// Mimic the native return format.
    		if ( $width && $height ) {
    			return array(
    				$width,
    				$height,
    				IMAGETYPE_WEBP,
    				sprintf(
    					'width="%d" height="%d"',
    					$width,
    					$height
    				),
    				'mime' => 'image/webp',
    			);
    		}
    	}

    	// For PHP versions that don't support AVIF images, extract the image size info from the file headers.
    	if ( 'image/avif' === $image_mime_type ) {
    		$avif_info = wp_get_avif_info( $filename );

    		$width  = $avif_info['width'];
    		$height = $avif_info['height'];

    		// Mimic the native return format.
    		if ( $width && $height ) {
    			return array(
    				$width,
    				$height,
    				IMAGETYPE_AVIF,
    				sprintf(
    					'width="%d" height="%d"',
    					$width,
    					$height
    				),
    				'mime' => 'image/avif',
    			);
    		}
    	}

    	// For PHP versions that don't support HEIC images, extract the size info using Imagick when available.
    	if ( wp_is_heic_image_mime_type( $image_mime_type ) ) {
    		$editor = wp_get_image_editor( $filename );

    		if ( is_wp_error( $editor ) ) {
    			return false;
    		}

    		// If the editor for HEICs is Imagick, use it to get the image size.
    		if ( $editor instanceof WP_Image_Editor_Imagick ) {
    			$size = $editor->get_size();
    			return array(
    				$size['width'],
    				$size['height'],
    				IMAGETYPE_HEIF,
    				sprintf(
    					'width="%d" height="%d"',
    					$size['width'],
    					$size['height']
    				),
    				'mime' => 'image/heic',
    			);
    		}
    	}

    	// The image could not be parsed.
    	return false;
    }
    ```

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

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

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

Checks if a mime type is for a HEIC/HEIF image.

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

Extracts meta information about an AVIF file: width, height, bit depth, and number of channels.

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

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

  | 
| [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.

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

Returns a [WP_Image_Editor](https://developer.wordpress.org/reference/classes/wp_image_editor/) instance and loads file into it.

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

Checks whether the given variable is a WordPress Error.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#)

| Used by | Description | 
| [wp_copy_parent_attachment_properties()](https://developer.wordpress.org/reference/functions/wp_copy_parent_attachment_properties/)`wp-admin/includes/image.php` |

Copy parent attachment properties to newly cropped image.

  | 
| [wp_get_missing_image_subsizes()](https://developer.wordpress.org/reference/functions/wp_get_missing_image_subsizes/)`wp-admin/includes/image.php` |

Compare the existing image sub-sizes (as saved in the attachment meta) to the currently registered image sub-sizes, and return the difference.

  | 
| [wp_create_image_subsizes()](https://developer.wordpress.org/reference/functions/wp_create_image_subsizes/)`wp-admin/includes/image.php` |

Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata.

  | 
| [WP_Site_Icon::create_attachment_object()](https://developer.wordpress.org/reference/classes/wp_site_icon/create_attachment_object/)`wp-admin/includes/class-wp-site-icon.php` |

Creates an attachment ‘object’.

  | 
| [wp_read_image_metadata()](https://developer.wordpress.org/reference/functions/wp_read_image_metadata/)`wp-admin/includes/image.php` |

Gets extended image metadata, exif or iptc as available.

  | 
| [file_is_valid_image()](https://developer.wordpress.org/reference/functions/file_is_valid_image/)`wp-admin/includes/image.php` |

Validates that file is an image.

  | 
| [file_is_displayable_image()](https://developer.wordpress.org/reference/functions/file_is_displayable_image/)`wp-admin/includes/image.php` |

Validates that file is suitable for displaying within a web page.

  | 
| [Custom_Image_Header::create_attachment_object()](https://developer.wordpress.org/reference/classes/custom_image_header/create_attachment_object/)`wp-admin/includes/class-custom-image-header.php` |

Creates an attachment ‘object’.

  | 
| [Custom_Image_Header::step_2()](https://developer.wordpress.org/reference/classes/custom_image_header/step_2/)`wp-admin/includes/class-custom-image-header.php` |

Displays second step of custom header image page.

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

Retrieve HTML content of icon attachment image element.

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

Sets or updates current image size.

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

Loads image from $this->file into new GD Resource.

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

Retrieves an image to represent an attachment.

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

Scales an image to fit a particular size (such as ‘thumb’ or ‘medium’).

  |

[Show 9 more](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#)

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

| Version | Description | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | Added support for AVIF images. | 
| [5.8.0](https://developer.wordpress.org/reference/since/5.8.0/) | Added support for WebP images. | 
| [5.7.0](https://developer.wordpress.org/reference/since/5.7.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_getimagesize/?output_format=md#comment-content-6417)
 2.   [Milana Cap](https://profiles.wordpress.org/milana_cap/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/wp_getimagesize/#comment-6417)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_getimagesize%2F%23comment-6417)
    Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_getimagesize%2F%23comment-6417)
 4. Usage (if you only have image URL):
 5.     ```php
        <?php
        $src          = 'https://example.com/path/to/image.jpg';
        $upload_dir   = wp_upload_dir();
        $image_path   = str_replace( $upload_dir[ 'baseurl' ], $upload_dir[ 'basedir' ], $src );
        $getimagesize = wp_getimagesize( $image_path );
        ?>
    
        <img <?php echo $getimagesize[3]; ?> src="<?php echo esc_url( $src ); ?>" />
        ```
    
 6. Returns array of data:
 7.     ```php
        $getimagesize[0]          = The width of the image.
        $getimagesize[1]          = The height of the image.
        $getimagesize[2]          = One of the IMAGETYPE_ constants indicating the type of the image.
        $getimagesize[3]          = A text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
        $getimagesize['mime']     = The correspondent MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header.
        $getimagesize['channels'] = 3 for RGB pictures and 4 for CMYK pictures.
        $getimagesize['bits']     = The number of bits for each color.
    
        Array
        (
            [0] => 440
            [1] => 95
            [2] => 3
            [3] => width="440" height="95"
            [bits] => 8
            [mime] => image/png
        )
        ```
    
 8.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_getimagesize%2F%3Freplytocom%3D6417%23feedback-editor-6417)

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