返回介绍

image_resize()

发布于 2017-09-11 01:01:14 字数 3190 浏览 1049 评论 0 收藏 0

Warning: This function has been deprecated. Use wp_get_image_editor() instead.

image_resize( string $file,  int $max_w,  int $max_h,  bool $crop = false,  string $suffix = null,  string $dest_path = null,  int $jpeg_quality = 90 )

Scale down an image to fit a particular size and save a new copy of the image.


description

The PNG transparency will be preserved using the function, as well as the image type. If the file going in is PNG, then the resized image is going to be PNG. The only supported image types are PNG, GIF, and JPEG.

Some functionality requires API to exist, so some PHP version may lose out support. This is not the fault of WordPress (where functionality is downgraded, not actual defects), but of your PHP version.


参数

$file

(string) (Required) Image file path.

$max_w

(int) (Required) Maximum width to resize to.

$max_h

(int) (Required) Maximum height to resize to.

$crop

(bool) (Optional) Whether to crop image or resize.

Default value: false

$suffix

(string) (Optional) File suffix.

Default value: null

$dest_path

(string) (Optional) New image file path.

Default value: null

$jpeg_quality

(int) (Optional) Image quality percentage.

Default value: 90


返回值

(mixed) WP_Error on failure. String with new destination path.


源代码

File: wp-includes/deprecated.php

function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
	_deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );

	$editor = wp_get_image_editor( $file );
	if ( is_wp_error( $editor ) )
		return $editor;
	$editor->set_quality( $jpeg_quality );

	$resized = $editor->resize( $max_w, $max_h, $crop );
	if ( is_wp_error( $resized ) )
		return $resized;

	$dest_file = $editor->generate_filename( $suffix, $dest_path );
	$saved = $editor->save( $dest_file );

	if ( is_wp_error( $saved ) )
		return $saved;

	return $dest_file;
}

更新日志

Versiondescription
3.5.0Use wp_get_image_editor()
2.5.0Introduced.

相关函数

Uses

  • wp-includes/functions.php: _deprecated_function()
  • wp-includes/media.php: wp_get_image_editor()
  • wp-includes/load.php: is_wp_error()

Used By

  • wp-admin/includes/deprecated.php: wp_create_thumbnail()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文