wp_stream_image
Streams image in WP_Image_Editor to browser.
Description
Provided for backcompat reasons
Parameters (3)
- 0. $image (WP_Image_Editor)
- The image.
- 1. $mime_type (string)
- The mime type.
- 2. $post_id (int)
- The post id.
Usage
if ( !function_exists( 'wp_stream_image' ) ) { require_once ABSPATH . '/wp-admin/includes/image-edit.php'; } // The image. $image = null; // The mime type. $mime_type = ''; // The post id. $post_id = -1; // NOTICE! Understand what this does before running. $result = wp_stream_image($image, $mime_type, $post_id);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/image-edit.php
- function wp_stream_image( $image, $mime_type, $post_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 WP_Image_Editor instance.
- * @param int $post_id Post ID.
- */
- $image = apply_filters( 'image_editor_save_pre', $image, $post_id );
- if ( is_wp_error( $image->stream( $mime_type ) ) )
- return false;
- return true;
- } else {
- _deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );
- /**
- * 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 $image Image resource to be streamed.
- * @param int $post_id Post ID.
- */
- $image = apply_filters( 'image_save_pre', $image, $post_id );
- 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 );
- default:
- return false;
- }
- }
- }