# wp_getimagesize()

URL: https://chugunov.pro/api-wordpress/functions/wp_getimagesize/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 5.7.0.

## Сигнатура

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

## Описание

Позволяет при необходимости отлаживать getimagesize() в PHP.

## Параметры

- `$filename` `string` — обязательный. Путь к файлу.
- `$image_info` `array` — необязательный, по умолчанию `null`. Расширенная информация об изображении (передаётся по ссылке).

## Возвращаемое значение

`array|false`

## Исходный код

Файл: `wp-includes/media.php:5728`

```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;
}
```

## История изменений

- 6.5.0 — Added support for AVIF images.
- 5.8.0 — Added support for WebP images.
- 5.7.0 — Introduced.

## Связанные

Использует: [`wp_is_heic_image_mime_type`](https://chugunov.pro/api-wordpress/functions/wp_is_heic_image_mime_type/), [`wp_get_avif_info`](https://chugunov.pro/api-wordpress/functions/wp_get_avif_info/), [`wp_get_webp_info`](https://chugunov.pro/api-wordpress/functions/wp_get_webp_info/), [`wp_get_image_mime`](https://chugunov.pro/api-wordpress/functions/wp_get_image_mime/), [`wp_get_image_editor`](https://chugunov.pro/api-wordpress/functions/wp_get_image_editor/), [`WP_Image_Editor`](https://chugunov.pro/api-wordpress/functions/wp_image_editor/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).
Используется в: [`wp_copy_parent_attachment_properties`](https://chugunov.pro/api-wordpress/functions/wp_copy_parent_attachment_properties/), [`wp_get_missing_image_subsizes`](https://chugunov.pro/api-wordpress/functions/wp_get_missing_image_subsizes/), [`wp_create_image_subsizes`](https://chugunov.pro/api-wordpress/functions/wp_create_image_subsizes/), `WP_Site_Icon::create_attachment_object`, [`wp_read_image_metadata`](https://chugunov.pro/api-wordpress/functions/wp_read_image_metadata/), [`file_is_valid_image`](https://chugunov.pro/api-wordpress/functions/file_is_valid_image/), [`file_is_displayable_image`](https://chugunov.pro/api-wordpress/functions/file_is_displayable_image/), `Custom_Image_Header::create_attachment_object`, `Custom_Image_Header::step_2`, [`get_attachment_icon`](https://chugunov.pro/api-wordpress/functions/get_attachment_icon/), `WP_Image_Editor_Imagick::update_size`, `WP_Image_Editor_GD::load`, [`wp_get_attachment_image_src`](https://chugunov.pro/api-wordpress/functions/wp_get_attachment_image_src/), [`image_downsize`](https://chugunov.pro/api-wordpress/functions/image_downsize/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_getimagesize/
