stream_preview_image

函式
stream_preview_image ( $post_id )
引數
  • (int) $post_id Attachment post ID.
    Required:
返回值
  • (bool) True on success, false on failure.
定義位置
相關方法
wp_stream_image_set_previewpost_previewis_random_header_imageget_previous_image_link
引入
2.9.0
棄用
-

stream_preview_image: 這是一個WordPress函式,為音訊或視訊檔案生成一個預覽影象。它需要兩個引數,$url和$post_id。$url引數指定音訊或視訊檔案的URL。$post_id引數是可選的,指定檔案所關聯的文章的ID。

將文章中的圖片和”$_REQUEST[‘history’]”中排隊的變化一起流向瀏覽器。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function stream_preview_image( $post_id ) {
$post = get_post( $post_id );
wp_raise_memory_limit( 'admin' );
$img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );
if ( is_wp_error( $img ) ) {
return false;
}
$changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null;
if ( $changes ) {
$img = image_edit_apply_changes( $img, $changes );
}
// Scale the image.
$size = $img->get_size();
$w = $size['width'];
$h = $size['height'];
$ratio = _image_get_preview_ratio( $w, $h );
$w2 = max( 1, $w * $ratio );
$h2 = max( 1, $h * $ratio );
if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) {
return false;
}
return wp_stream_image( $img, $post->post_mime_type, $post_id );
}
function stream_preview_image( $post_id ) { $post = get_post( $post_id ); wp_raise_memory_limit( 'admin' ); $img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) ); if ( is_wp_error( $img ) ) { return false; } $changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null; if ( $changes ) { $img = image_edit_apply_changes( $img, $changes ); } // Scale the image. $size = $img->get_size(); $w = $size['width']; $h = $size['height']; $ratio = _image_get_preview_ratio( $w, $h ); $w2 = max( 1, $w * $ratio ); $h2 = max( 1, $h * $ratio ); if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) { return false; } return wp_stream_image( $img, $post->post_mime_type, $post_id ); }
function stream_preview_image( $post_id ) {
	$post = get_post( $post_id );

	wp_raise_memory_limit( 'admin' );

	$img = wp_get_image_editor( _load_image_to_edit_path( $post_id ) );

	if ( is_wp_error( $img ) ) {
		return false;
	}

	$changes = ! empty( $_REQUEST['history'] ) ? json_decode( wp_unslash( $_REQUEST['history'] ) ) : null;
	if ( $changes ) {
		$img = image_edit_apply_changes( $img, $changes );
	}

	// Scale the image.
	$size = $img->get_size();
	$w    = $size['width'];
	$h    = $size['height'];

	$ratio = _image_get_preview_ratio( $w, $h );
	$w2    = max( 1, $w * $ratio );
	$h2    = max( 1, $h * $ratio );

	if ( is_wp_error( $img->resize( $w2, $h2 ) ) ) {
		return false;
	}

	return wp_stream_image( $img, $post->post_mime_type, $post_id );
}

常見問題

FAQs
檢視更多 >