Uma área de pesquisa sobre o WordPress para devs e autores do tema



wp_stream_image ›

Desden/a
Obsoleton/a
wp_stream_image ( $image, $mime_type, $attachment_id )
Parâmetros: (3)
  • (WP_Image_Editor) $image The image editor instance.
    Required: Yes
  • (string) $mime_type The mime type of the image.
    Required: Yes
  • (int) $attachment_id The image's attachment post ID.
    Required: Yes
Retorna:
  • (bool) True on success, false on failure.
Definido em:
Codex:

Streams image in WP_Image_Editor to browser.



Fonte

function wp_stream_image( $image, $mime_type, $attachment_id ) {
	if ( $image instanceof WP_Image_Editor ) {

		/**
		 * Filters the WP_Image_Editor instance for the image to be streamed to the browser.
		 *
		 * @since 3.5.0
		 *
		 * @param WP_Image_Editor $image         The image editor instance.
		 * @param int             $attachment_id The attachment post ID.
		 */
		$image = apply_filters( 'image_editor_save_pre', $image, $attachment_id );

		if ( is_wp_error( $image->stream( $mime_type ) ) )
			return false;

		return true;
	} else {
		_deprecated_argument( __FUNCTION__, '3.5.0', __( '$image needs to be an WP_Image_Editor object' ) );

		/**
		 * Filters the GD image resource to be streamed to the browser.
		 *
		 * @since 2.9.0
		 * @deprecated 3.5.0 Use image_editor_save_pre instead.
		 *
		 * @param resource $image         Image resource to be streamed.
		 * @param int      $attachment_id The attachment post ID.
		 */
		$image = apply_filters( 'image_save_pre', $image, $attachment_id );

		switch ( $mime_type ) {
			case 'image/jpeg':
				header( 'Content-Type: image/jpeg' );
				return imagejpeg( $image, null, 90 );
			case 'image/png':
				header( 'Content-Type: image/png' );
				return imagepng( $image );
			case 'image/gif':
				header( 'Content-Type: image/gif' );
				return imagegif( $image );
			default:
				return false;
		}
	}
}