wp_stream_image

Streams image in WP_Image_Editor to browser.

Description

wp_stream_image( (WP_Image_Editor) $image, (string) $mime_type, (int) $post_id ); 

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

  1. if ( !function_exists( 'wp_stream_image' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/image-edit.php'; 
  3.  
  4. // The image. 
  5. $image = null; 
  6.  
  7. // The mime type. 
  8. $mime_type = ''; 
  9.  
  10. // The post id. 
  11. $post_id = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_stream_image($image, $mime_type, $post_id); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/image-edit.php  
  1. function wp_stream_image( $image, $mime_type, $post_id ) { 
  2. if ( $image instanceof WP_Image_Editor ) { 
  3.  
  4. /** 
  5. * Filters the WP_Image_Editor instance for the image to be streamed to the browser. 
  6. * @since 3.5.0 
  7. * @param WP_Image_Editor $image WP_Image_Editor instance. 
  8. * @param int $post_id Post ID. 
  9. */ 
  10. $image = apply_filters( 'image_editor_save_pre', $image, $post_id ); 
  11.  
  12. if ( is_wp_error( $image->stream( $mime_type ) ) ) 
  13. return false; 
  14.  
  15. return true; 
  16. } else { 
  17. _deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) ); 
  18.  
  19. /** 
  20. * Filters the GD image resource to be streamed to the browser. 
  21. * @since 2.9.0 
  22. * @deprecated 3.5.0 Use image_editor_save_pre instead. 
  23. * @param resource $image Image resource to be streamed. 
  24. * @param int $post_id Post ID. 
  25. */ 
  26. $image = apply_filters( 'image_save_pre', $image, $post_id ); 
  27.  
  28. switch ( $mime_type ) { 
  29. case 'image/jpeg': 
  30. header( 'Content-Type: image/jpeg' ); 
  31. return imagejpeg( $image, null, 90 ); 
  32. case 'image/png': 
  33. header( 'Content-Type: image/png' ); 
  34. return imagepng( $image ); 
  35. case 'image/gif': 
  36. header( 'Content-Type: image/gif' ); 
  37. return imagegif( $image ); 
  38. default: 
  39. return false;