# wp_stream_image()

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

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

## Сигнатура

```php
wp_stream_image( WP_Image_Editor $image, string $mime_type, int $attachment_id ): bool
```

## Описание

Передаёт изображение из WP_Image_Editor в браузер.

## Параметры

- `$image` `WP_Image_Editor` — обязательный. Экземпляр редактора изображений.
- `$mime_type` `string` — обязательный. MIME-тип изображения.
- `$attachment_id` `int` — обязательный. Идентификатор записи-вложения изображения.

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

`bool`

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

Файл: `wp-admin/includes/image-edit.php:344`

```php
function wp_stream_image( $image, $mime_type, $attachment_id ) {
	if ( $image instanceof WP_Image_Editor ) {

		/**
		 * Filters the WP_Image_Editor instance for the image to be streamed to the browser.
		 *
		 * @since 3.5.0
		 *
		 * @param WP_Image_Editor $image         The image editor instance.
		 * @param int             $attachment_id The attachment post ID.
		 */
		$image = apply_filters( 'image_editor_save_pre', $image, $attachment_id );

		if ( is_wp_error( $image->stream( $mime_type ) ) ) {
			return false;
		}

		return true;
	} else {
		/* translators: 1: $image, 2: WP_Image_Editor */
		_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) );

		/**
		 * Filters the GD image resource to be streamed to the browser.
		 *
		 * @since 2.9.0
		 * @deprecated 3.5.0 Use 'image_editor_save_pre' instead.
		 *
		 * @param resource|GdImage $image         Image resource to be streamed.
		 * @param int              $attachment_id The attachment post ID.
		 */
		$image = apply_filters_deprecated( 'image_save_pre', array( $image, $attachment_id ), '3.5.0', 'image_editor_save_pre' );

		switch ( $mime_type ) {
			case 'image/jpeg':
				header( 'Content-Type: image/jpeg' );
				return imagejpeg( $image, null, 90 );
			case 'image/png':
				header( 'Content-Type: image/png' );
				return imagepng( $image );
			case 'image/gif':
				header( 'Content-Type: image/gif' );
				return imagegif( $image );
			case 'image/webp':
				if ( function_exists( 'imagewebp' ) ) {
					header( 'Content-Type: image/webp' );
					return imagewebp( $image, null, 90 );
				}
				return false;
			case 'image/avif':
				if ( function_exists( 'imageavif' ) ) {
					header( 'Content-Type: image/avif' );
					return imageavif( $image, null, 90 );
				}
				return false;
			default:
				return false;
		}
	}
}
```

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

- 2.9.0 — Introduced.

## Связанные

Использует: [`apply_filters_deprecated`](https://chugunov.pro/api-wordpress/functions/apply_filters_deprecated/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`_deprecated_argument`](https://chugunov.pro/api-wordpress/functions/_deprecated_argument/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`is_wp_error`](https://chugunov.pro/api-wordpress/functions/is_wp_error/).
Используется в: [`stream_preview_image`](https://chugunov.pro/api-wordpress/functions/stream_preview_image/).

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