WP_Image_Editor_GD::stream() WordPress Method

The GD library is used for image manipulation within WordPress. The stream() function allows for the output of an image to a browser as a stream of data. This can be useful for outputting images that are generated on the fly and do not need to be saved as a file.

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

Returns stream of current image.


Parameters

$mime_type

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

Default value: null


Top ↑

Return

(bool) True on success, false on failure.


Top ↑

Source

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

	public function stream( $mime_type = null ) {
		list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type );

		switch ( $mime_type ) {
			case 'image/png':
				header( 'Content-Type: image/png' );
				return imagepng( $this->image );
			case 'image/gif':
				header( 'Content-Type: image/gif' );
				return imagegif( $this->image );
			case 'image/webp':
				if ( function_exists( 'imagewebp' ) ) {
					header( 'Content-Type: image/webp' );
					return imagewebp( $this->image, null, $this->get_quality() );
				}
				// Fall back to the default if webp isn't supported.
			default:
				header( 'Content-Type: image/jpeg' );
				return imagejpeg( $this->image, null, $this->get_quality() );
		}
	}

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.