stream_preview_image

The timeline below displays how wordpress function stream_preview_image has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.4

/**
 * Streams image in post to browser, along with enqueued changes
 * in `$_REQUEST['history']`.
 *
 * @since 2.9.0
 *
 * @param int $post_id Attachment post ID.
 * @return bool True on success, false on failure.
 */
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);
}

WordPress Version: 5.1

/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @since 2.9.0
 *
 * @param int $post_id
 * @return bool
 */
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);
}

WordPress Version: 4.6

/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return bool
 */
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);
}

WordPress Version: 4.3

/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return bool
 */
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    /** This filter is documented in wp-admin/admin.php */
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $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);
}

WordPress Version: 4.0

/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return boolean
 */
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    /** This filter is documented in wp-admin/admin.php */
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $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);
}

WordPress Version: 3.9

/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return boolean
 */
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    /** This filter is documented in wp-admin/admin.php */
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $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);
}

WordPress Version: 3.7

/**
 * Streams image in post to browser, along with enqueued changes
 * in $_REQUEST['history']
 *
 * @param int $post_id
 * @return boolean
 */
function stream_preview_image($post_id)
{
    $post = get_post($post_id);
    @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
    $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);
}