W3cubDocs

/WordPress

WP_Image_Editor_Imagick::stream( string $mime_type = null )

Streams current image to browser.

Description

Parameters

$mime_type

(string) (Optional) The mime type of the image.

Default value: null

Return

(bool|WP_Error) True on success, WP_Error object on failure.

Source

File: wp-includes/class-wp-image-editor-imagick.php

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;
	}

Changelog

Version Description
3.5.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_image_editor_imagick/stream