wp_stream_image
函数
wp_stream_image ( $image, $mime_type, $attachment_id )
- 参数
-
-
(WP_Image_Editor)
$image
The image editor instance.- Required: 是
-
(string)
$mime_type
The mime type of the image.- Required: 是
-
(int)
$attachment_id
The image’s attachment post ID.- Required: 是
-
(WP_Image_Editor)
- 返回值
-
- (bool) True on success, false on failure.
- 定义位置
-
-
wp-admin/includes/image-edit.php
, line 295
-
wp-admin/includes/image-edit.php
- 引入
- 2.9.0
- 弃用
- –
Streams image in WP_Image_Editor to browser.
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 {
/* translators: 1: $image, 2: WP_Image_Editor */
_deprecated_argument( __FUNCTION__, '3.5.0', sprintf( __( '%1$s needs to be a %2$s object.' ), '$image', 'WP_Image_Editor' ) );
/**
* Filters the GD image resource to be streamed to the browser.
*
* @since 2.9.0
* @deprecated 3.5.0 Use {@see 'image_editor_save_pre'} instead.
*
* @param resource|GdImage $image Image resource to be streamed.
* @param int $attachment_id The attachment post ID.
*/
$image = apply_filters_deprecated( 'image_save_pre', array( $image, $attachment_id ), '3.5.0', 'image_editor_save_pre' );
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 );
case 'image/webp':
if ( function_exists( 'imagewebp' ) ) {
header( 'Content-Type: image/webp' );
return imagewebp( $image, null, 90 );
}
return false;
default:
return false;
}
}
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。