wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_image_matches_ratio › WordPress Function
Seit4.6.0
Veraltetn/v
› wp_image_matches_ratio ( $source_width, $source_height, $target_width, $target_height )
| Parameter: (4) |
|
| Gibt zurück: |
|
| Definiert in: |
|
| Codex: |
Helper function to test if aspect ratios for two images match.
Ähnliche Funktionen: wp_get_attachment_caption, wp_media_attach_action, wp_image_file_matches_image_meta, wp_image_editor, wp_mime_type_icon
Quellcode
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;
}