BP_Attachment::get_image_data( string $file )
Get full data for an image
Description
Parameters
- $file
-
(Required) Absolute path to the uploaded image.
Return
(bool|array) An associate array containing the width, height and metadatas. False in case an important image attribute is missing.
Source
File: bp-core/classes/class-bp-attachment.php
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | public static function get_image_data( $file ) { // Try to get image basic data. list( $width , $height , $sourceImageType ) = @ getimagesize ( $file ); // No need to carry on if we couldn't get image's basic data. if ( is_null ( $width ) || is_null ( $height ) || is_null ( $sourceImageType ) ) { return false; } // Initialize the image data. $image_data = array ( 'width' => $width , 'height' => $height , ); /** * Make sure the wp_read_image_metadata function is reachable for the old Avatar UI * or if WordPress < 3.9 (New Avatar UI is not available in this case) */ if ( ! function_exists( 'wp_read_image_metadata' ) ) { require_once ( ABSPATH . 'wp-admin/includes/image.php' ); } // Now try to get image's meta data. $meta = wp_read_image_metadata( $file ); if ( ! empty ( $meta ) ) { $image_data [ 'meta' ] = $meta ; } /** * Filter here to add/remove/edit data to the image full data * * @since BuddyPress 2.4.0 * * @param array $image_data An associate array containing the width, height and metadatas. */ return apply_filters( 'bp_attachments_get_image_data' , $image_data ); } |
Changelog
Version | Description |
---|---|
BuddyPress 2.4.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.