wp_load_image

函数
wp_load_image ( $file )
参数
  • (string) $file Filename of the image to load.
    Required:
返回值
  • (resource|GdImage|string) The resulting image resource or GdImage instance on success, error string on failure.
相关
  • wp_get_image_editor()
定义位置
相关方法
wp_crop_imagewp_save_imagewp_preload_dialogswp_stream_imagemedia_upload_image
引入
2.1.0
弃用
3.5.0

wp_load_image: 这个函数从指定路径加载一个图像文件,并根据文件类型创建一个图像资源。它支持各种图像格式,如JPEG、PNG、GIF和BMP。

如果PHP支持的话,从一个字符串中加载一个图像。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_load_image( $file ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );
if ( is_numeric( $file ) )
$file = get_attached_file( $file );
if ( ! is_file( $file ) ) {
/* translators: %s: File name. */
return sprintf( __( 'File “%s” does not exist?' ), $file );
}
if ( ! function_exists('imagecreatefromstring') )
return __('The GD image library is not installed.');
// Set artificially high because GD uses uncompressed images in memory.
wp_raise_memory_limit( 'image' );
$image = imagecreatefromstring( file_get_contents( $file ) );
if ( ! is_gd_image( $image ) ) {
/* translators: %s: File name. */
return sprintf( __( 'File “%s” is not an image.' ), $file );
}
return $image;
}
function wp_load_image( $file ) { _deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' ); if ( is_numeric( $file ) ) $file = get_attached_file( $file ); if ( ! is_file( $file ) ) { /* translators: %s: File name. */ return sprintf( __( 'File “%s” does not exist?' ), $file ); } if ( ! function_exists('imagecreatefromstring') ) return __('The GD image library is not installed.'); // Set artificially high because GD uses uncompressed images in memory. wp_raise_memory_limit( 'image' ); $image = imagecreatefromstring( file_get_contents( $file ) ); if ( ! is_gd_image( $image ) ) { /* translators: %s: File name. */ return sprintf( __( 'File “%s” is not an image.' ), $file ); } return $image; }
function wp_load_image( $file ) {
	_deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );

	if ( is_numeric( $file ) )
		$file = get_attached_file( $file );

	if ( ! is_file( $file ) ) {
		/* translators: %s: File name. */
		return sprintf( __( 'File “%s” does not exist?' ), $file );
	}

	if ( ! function_exists('imagecreatefromstring') )
		return __('The GD image library is not installed.');

	// Set artificially high because GD uses uncompressed images in memory.
	wp_raise_memory_limit( 'image' );

	$image = imagecreatefromstring( file_get_contents( $file ) );

	if ( ! is_gd_image( $image ) ) {
		/* translators: %s: File name. */
		return sprintf( __( 'File “%s” is not an image.' ), $file );
	}

	return $image;
}

常见问题

FAQs
查看更多 >