Uses
Uses | Description |
---|---|
wp-includes/media.php: wp_image_file_matches_image_meta() | Determines if the image meta data is for the image source file. |
wp-includes/formatting.php: wp_basename() | i18n friendly version of basename() |
Determines an image’s width and height dimensions based on the source file.
(string) (Required) The image source file.
(array) (Required) The image meta data as returned by 'wp_get_attachment_metadata()'.
(int) (Optional) The image attachment ID. Default 0.
(array|false) Array with first element being the width and second element being the height, or false if dimensions cannot be determined.
File: wp-includes/media.php
function wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id = 0 ) { if ( ! wp_image_file_matches_image_meta( $image_src, $image_meta, $attachment_id ) ) { return false; } // Is it a full size image? if ( strpos( $image_src, $image_meta['file'] ) !== false ) { return array( (int) $image_meta['width'], (int) $image_meta['height'], ); } if ( ! empty( $image_meta['sizes'] ) ) { $src_filename = wp_basename( $image_src ); foreach ( $image_meta['sizes'] as $image_size_data ) { if ( $src_filename === $image_size_data['file'] ) { return array( (int) $image_size_data['width'], (int) $image_size_data['height'], ); } } } return false; }
Version | Description |
---|---|
5.5.0 | Introduced. |
© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_image_src_get_dimensions