返回介绍

wp_image_matches_ratio()

发布于 2017-09-11 12:11:54 字数 2386 浏览 952 评论 0 收藏 0

wp_image_matches_ratio( int $源代码_width,  int $源代码_height,  int $target_width,  int $target_height )

Helper function to test if aspect ratios for two images match.


description


参数

$源代码_width

(int) (Required) Width of the first image in pixels.

$源代码_height

(int) (Required) Height of the first image in pixels.

$target_width

(int) (Required) Width of the second image in pixels.

$target_height

(int) (Required) Height of the second image in pixels.


返回值

(bool) True if aspect ratios match within 1px. False if not.


源代码

File: wp-includes/media.php

function wp_image_matches_ratio( $源代码_width, $源代码_height, $target_width, $target_height ) {
	/*
	 * To test for varying crops, we constrain the dimensions of the larger image
	 * to the dimensions of the smaller image and see if they match.
	 */
	if ( $源代码_width > $target_width ) {
		$constrained_size = wp_constrain_dimensions( $源代码_width, $源代码_height, $target_width );
		$expected_size = array( $target_width, $target_height );
	} else {
		$constrained_size = wp_constrain_dimensions( $target_width, $target_height, $源代码_width );
		$expected_size = array( $源代码_width, $源代码_height );
	}

	// If the image dimensions are within 1px of the expected size, we consider it a match.
	$matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 );

	return $matched;
}

更新日志

Versiondescription
4.6.0Introduced.

相关函数

Uses

  • wp-includes/media.php: wp_constrain_dimensions()

Used By

  • wp-includes/media.php: wp_calculate_image_srcset()
  • wp-includes/media.php: image_get_intermediate_size()

User Contributed Notes

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

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

发布评论

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