wp_stream_image

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

WordPress Version: 6.5

/**
 * Streams image in WP_Image_Editor to browser.
 *
 * @since 2.9.0
 *
 * @param WP_Image_Editor $image         The image editor instance.
 * @param string          $mime_type     The mime type of the image.
 * @param int             $attachment_id The image's attachment post ID.
 * @return bool True on success, false on failure.
 */
function wp_stream_image($image, $mime_type, $attachment_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         The image editor instance.
         * @param int             $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_editor_save_pre', $image, $attachment_id);
        if (is_wp_error($image->stream($mime_type))) {
            return false;
        }
        return true;
    } else {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /**
         * Filters the GD image resource to be streamed to the browser.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead.
         *
         * @param resource|GdImage $image         Image resource to be streamed.
         * @param int              $attachment_id The attachment post ID.
         */
        $image = apply_filters_deprecated('image_save_pre', array($image, $attachment_id), '3.5.0', 'image_editor_save_pre');
        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);
            case 'image/webp':
                if (function_exists('imagewebp')) {
                    header('Content-Type: image/webp');
                    return imagewebp($image, null, 90);
                }
                return false;
            case 'image/avif':
                if (function_exists('imageavif')) {
                    header('Content-Type: image/avif');
                    return imageavif($image, null, 90);
                }
                return false;
            default:
                return false;
        }
    }
}

WordPress Version: 5.8

/**
 * Streams image in WP_Image_Editor to browser.
 *
 * @since 2.9.0
 *
 * @param WP_Image_Editor $image         The image editor instance.
 * @param string          $mime_type     The mime type of the image.
 * @param int             $attachment_id The image's attachment post ID.
 * @return bool True on success, false on failure.
 */
function wp_stream_image($image, $mime_type, $attachment_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         The image editor instance.
         * @param int             $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_editor_save_pre', $image, $attachment_id);
        if (is_wp_error($image->stream($mime_type))) {
            return false;
        }
        return true;
    } else {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /**
         * Filters the GD image resource to be streamed to the browser.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead.
         *
         * @param resource|GdImage $image         Image resource to be streamed.
         * @param int              $attachment_id The attachment post ID.
         */
        $image = apply_filters_deprecated('image_save_pre', array($image, $attachment_id), '3.5.0', 'image_editor_save_pre');
        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);
            case 'image/webp':
                if (function_exists('imagewebp')) {
                    header('Content-Type: image/webp');
                    return imagewebp($image, null, 90);
                }
                return false;
            default:
                return false;
        }
    }
}

WordPress Version: 5.6

/**
 * Streams image in WP_Image_Editor to browser.
 *
 * @since 2.9.0
 *
 * @param WP_Image_Editor $image         The image editor instance.
 * @param string          $mime_type     The mime type of the image.
 * @param int             $attachment_id The image's attachment post ID.
 * @return bool True on success, false on failure.
 */
function wp_stream_image($image, $mime_type, $attachment_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         The image editor instance.
         * @param int             $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_editor_save_pre', $image, $attachment_id);
        if (is_wp_error($image->stream($mime_type))) {
            return false;
        }
        return true;
    } else {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /**
         * Filters the GD image resource to be streamed to the browser.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead.
         *
         * @param resource|GdImage $image         Image resource to be streamed.
         * @param int              $attachment_id The attachment post ID.
         */
        $image = apply_filters_deprecated('image_save_pre', array($image, $attachment_id), '3.5.0', 'image_editor_save_pre');
        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;
        }
    }
}

WordPress Version: 5.4

/**
 * Streams image in WP_Image_Editor to browser.
 *
 * @since 2.9.0
 *
 * @param WP_Image_Editor $image         The image editor instance.
 * @param string          $mime_type     The mime type of the image.
 * @param int             $attachment_id The image's attachment post ID.
 * @return bool True on success, false on failure.
 */
function wp_stream_image($image, $mime_type, $attachment_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         The image editor instance.
         * @param int             $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_editor_save_pre', $image, $attachment_id);
        if (is_wp_error($image->stream($mime_type))) {
            return false;
        }
        return true;
    } else {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /**
         * Filters the GD image resource to be streamed to the browser.
         *
         * @since 2.9.0
         * @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead.
         *
         * @param resource $image         Image resource to be streamed.
         * @param int      $attachment_id The attachment post ID.
         */
        $image = apply_filters_deprecated('image_save_pre', array($image, $attachment_id), '3.5.0', 'image_editor_save_pre');
        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;
        }
    }
}

WordPress Version: 5.3

/**
 * Streams image in WP_Image_Editor to browser.
 *
 * @since 2.9.0
 *
 * @param WP_Image_Editor $image         The image editor instance.
 * @param string          $mime_type     The mime type of the image.
 * @param int             $attachment_id The image's attachment post ID.
 * @return bool True on success, false on failure.
 */
function wp_stream_image($image, $mime_type, $attachment_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         The image editor instance.
         * @param int             $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_editor_save_pre', $image, $attachment_id);
        if (is_wp_error($image->stream($mime_type))) {
            return false;
        }
        return true;
    } else {
        /* translators: 1: $image, 2: WP_Image_Editor */
        _deprecated_argument(__FUNCTION__, '3.5.0', sprintf(__('%1$s needs to be a %2$s object.'), '$image', 'WP_Image_Editor'));
        /**
         * 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      $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_save_pre', $image, $attachment_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;
        }
    }
}

WordPress Version: 5.1

/**
 * Streams image in WP_Image_Editor to browser.
 *
 * @since 2.9.0
 *
 * @param WP_Image_Editor $image         The image editor instance.
 * @param string          $mime_type     The mime type of the image.
 * @param int             $attachment_id The image's attachment post ID.
 * @return bool True on success, false on failure.
 */
function wp_stream_image($image, $mime_type, $attachment_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         The image editor instance.
         * @param int             $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_editor_save_pre', $image, $attachment_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      $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_save_pre', $image, $attachment_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;
        }
    }
}

WordPress Version: 4.9

/**
 * Streams image in WP_Image_Editor to browser.
 *
 * @param WP_Image_Editor $image         The image editor instance.
 * @param string          $mime_type     The mime type of the image.
 * @param int             $attachment_id The image's attachment post ID.
 * @return bool True on success, false on failure.
 */
function wp_stream_image($image, $mime_type, $attachment_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         The image editor instance.
         * @param int             $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_editor_save_pre', $image, $attachment_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      $attachment_id The attachment post ID.
         */
        $image = apply_filters('image_save_pre', $image, $attachment_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;
        }
    }
}

WordPress Version: 4.6

/**
 * Streams image in WP_Image_Editor to browser.
 * Provided for backcompat reasons
 *
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return bool
 */
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;
        }
    }
}

WordPress Version: 4.3

/**
 * Streams image in WP_Image_Editor to browser.
 * Provided for backcompat reasons
 *
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return bool
 */
function wp_stream_image($image, $mime_type, $post_id)
{
    if ($image instanceof WP_Image_Editor) {
        /**
         * Filter 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', __('$image needs to be an WP_Image_Editor object'));
        /**
         * Filter 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;
        }
    }
}

WordPress Version: 3.9

/**
 * Streams image in WP_Image_Editor to browser.
 * Provided for backcompat reasons
 *
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return boolean
 */
function wp_stream_image($image, $mime_type, $post_id)
{
    if ($image instanceof WP_Image_Editor) {
        /**
         * Filter 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', __('$image needs to be an WP_Image_Editor object'));
        /**
         * Filter 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;
        }
    }
}

WordPress Version: 3.7

/**
 * Streams image in WP_Image_Editor to browser.
 * Provided for backcompat reasons
 *
 * @param WP_Image_Editor $image
 * @param string $mime_type
 * @param int $post_id
 * @return boolean
 */
function wp_stream_image($image, $mime_type, $post_id)
{
    if ($image instanceof WP_Image_Editor) {
        $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', __('$image needs to be an WP_Image_Editor object'));
        $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;
        }
    }
}