stream_preview_image

Streams image in post to browser, along with enqueued changes in $_REQUEST['history'].

Description

stream_preview_image( (int) $post_id ); 

Parameters (1)

0. $post_id (int)
The post id.

Usage

  1. if ( !function_exists( 'stream_preview_image' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/image-edit.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = stream_preview_image($post_id); 
  9.  

Defined (1)

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

/wp-admin/includes/image-edit.php  
  1. function stream_preview_image( $post_id ) { 
  2. $post = get_post( $post_id ); 
  3.  
  4. wp_raise_memory_limit( 'admin' ); 
  5.  
  6.  
  7. if ( is_wp_error( $img ) ) { 
  8. return false; 
  9.  
  10. $changes = !empty($_REQUEST['history']) ? json_decode( wp_unslash($_REQUEST['history']) ) : null; 
  11. if ( $changes ) 
  12. $img = image_edit_apply_changes( $img, $changes ); 
  13.  
  14. // Scale the image. 
  15. $size = $img->get_size(); 
  16. $w = $size['width']; 
  17. $h = $size['height']; 
  18.  
  19. $ratio = _image_get_preview_ratio( $w, $h ); 
  20. $w2 = max ( 1, $w * $ratio ); 
  21. $h2 = max ( 1, $h * $ratio ); 
  22.  
  23. if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) 
  24. return false; 
  25.  
  26. return wp_stream_image( $img, $post->post_mime_type, $post_id );