WP_Image_Editor_Imagick::stream PHP Method

stream() public method

Streams current image to browser.
Since: 3.5.0
public stream ( string $mime_type = null ) : true | WP_Error
$mime_type string
return true | WP_Error
    public function stream($mime_type = null)
    {
        list($filename, $extension, $mime_type) = $this->get_output_format(null, $mime_type);
        try {
            // Temporarily change format for stream
            $this->image->setImageFormat(strtoupper($extension));
            // Output stream of image content
            header("Content-Type: {$mime_type}");
            print $this->image->getImageBlob();
            // Reset Image to original Format
            $this->image->setImageFormat($this->get_extension($this->mime_type));
        } catch (Exception $e) {
            return new WP_Error('image_stream_error', $e->getMessage());
        }
        return true;
    }