wp_image_matches_ratio
函数
wp_image_matches_ratio ( $source_width, $source_height, $target_width, $target_height )
- 参数
-
-
(int)
$source_width
Width of the first image in pixels.- Required: 是
-
(int)
$source_height
Height of the first image in pixels.- Required: 是
-
(int)
$target_width
Width of the second image in pixels.- Required: 是
-
(int)
$target_height
Height of the second image in pixels.- Required: 是
-
(int)
- 返回值
-
- (bool) True if aspect ratios match within 1px. False if not.
- 定义位置
-
-
wp-includes/media.php
, line 705
-
wp-includes/media.php
- 引入
- 4.6.0
- 弃用
- –
Helper function to test if aspect ratios for two images match.
function wp_image_matches_ratio( $source_width, $source_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 ( $source_width > $target_width ) { $constrained_size = wp_constrain_dimensions( $source_width, $source_height, $target_width ); $expected_size = array( $target_width, $target_height ); } else { $constrained_size = wp_constrain_dimensions( $target_width, $target_height, $source_width ); $expected_size = array( $source_width, $source_height ); } // If the image dimensions are within 1px of the expected size, we consider it a match. $matched = ( wp_fuzzy_number_match( $constrained_size[0], $expected_size[0] ) && wp_fuzzy_number_match( $constrained_size[1], $expected_size[1] ) ); return $matched; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。