WP_Image_Editor_Imagick::stream() WordPress Method

The WP_Image_Editor_Imagick::stream() function is used to output an image to the browser. It can be used to output a single image or multiple images in a slideshow format. The function can be used to output images in various formats, including JPEG, PNG, and GIF.

WP_Image_Editor_Imagick::stream( string $mime_type = null ) #

Streams current image to browser.


Parameters

$mime_type

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

Default value: null


Top ↑

Return

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


Top ↑

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


Top ↑

Changelog

Changelog
VersionDescription
3.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.