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
Return
(true|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; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.5.0 | Introduced. |