функция
since 4.6.0
wp_image_matches_ratio()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
wp_image_matches_ratio( int $source_width, int $source_height, int $target_width, int $target_height ): bool
Описание
Вспомогательная функция для проверки совпадения соотношения сторон двух изображений.
Параметры
$source_width
int
обязательный
Ширина первого изображения в пикселях.
$source_height
int
обязательный
Высота первого изображения в пикселях.
$target_width
int
обязательный
Ширина второго изображения в пикселях.
$target_height
int
обязательный
Высота второго изображения в пикселях.
Возвращаемое значение
bool
Исходный код
wp-includes/media.php:726
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 px 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;
}
История изменений
| Версия | Описание |
|---|---|
| 4.6.0 | Introduced. |

