stream_preview_image() – Streams image in post to browser, along with enqueued changes in $_REQUEST[’history’]

You appear to be a bot. Output may be restricted

Description

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

Usage

$bool = stream_preview_image( $post_id );

Parameters

$post_id
( int ) required – Attachment post ID.

Returns

bool True on success, false on failure.

Source

File name: wordpress/wp-admin/includes/image-edit.php
Lines:

1 to 31 of 31
function stream_preview_image( $post_id ) {
  $post = get_post( $post_id );

  wp_raise_memory_limit( 'admin' );

  $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );

  if ( is_wp_error( $img ) ) {
    return false;
  }

  $changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null;
  if ( $changes ) {
    $img = image_edit_apply_changes( $img, $changes );
  }

  // Scale the image.
  $size = $img->get_size();
  $w    = $size['width'];
  $h    = $size['height'];

  $ratio = _image_get_preview_ratio( $w, $h );
  $w2    = max( 1, $w * $ratio );
  $h2    = max( 1, $h * $ratio );

  if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) {
    return false;
  }

  return wp_stream_image( $img, $post->post_mime_type, $post_id );
}
 

 View on GitHub View on Trac