wp_image_src_get_dimensions
函数
wp_image_src_get_dimensions ( $image_src, $image_meta, $attachment_id = 0 )
- 参数
-
-
(string)
$image_src
The image source file.- Required: 是
-
(array)
$image_meta
The image meta data as returned by ‘wp_get_attachment_metadata()’.- Required: 是
-
(int)
$attachment_id
Optional. The image attachment ID. Default 0.- Required: 否
-
(string)
- 返回值
-
- (array|false) Array with first element being the width and second element being the height, or false if dimensions cannot be determined.
- 定义位置
-
-
wp-includes/media.php
, line 1607
-
wp-includes/media.php
- 引入
- 5.5.0
- 弃用
- –
Determines an image’s width and height dimensions based on the source file.
function wp_image_src_get_dimensions( $image_src, $image_meta, $attachment_id = 0 ) {
$dimensions = false;
// Is it a full size image?
if (
isset( $image_meta['file'] ) &&
strpos( $image_src, wp_basename( $image_meta['file'] ) ) !== false
) {
$dimensions = array(
(int) $image_meta['width'],
(int) $image_meta['height'],
);
}
if ( ! $dimensions && ! 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'] ) {
$dimensions = array(
(int) $image_size_data['width'],
(int) $image_size_data['height'],
);
break;
}
}
}
/**
* Filters the 'wp_image_src_get_dimensions' value.
*
* @since 5.7.0
*
* @param array|false $dimensions Array with first element being the width
* and second element being the height, or
* false if dimensions could not be determined.
* @param string $image_src The image source file.
* @param array $image_meta The image meta data as returned by
* 'wp_get_attachment_metadata()'.
* @param int $attachment_id The image attachment ID. Default 0.
*/
return apply_filters( 'wp_image_src_get_dimensions', $dimensions, $image_src, $image_meta, $attachment_id );
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。