Skip to:
Content

BuddyPress.org

Ticket #5089: 5089.03.patch

File 5089.03.patch, 2.4 KB (added by r-a-y, 11 years ago)
  • src/bp-core/classes/class-bp-attachment-avatar.php

    diff --git src/bp-core/classes/class-bp-attachment-avatar.php src/bp-core/classes/class-bp-attachment-avatar.php
    index 980b1bc..686e55e 100644
    class BP_Attachment_Avatar extends BP_Attachment { 
    137137                        if ( ! is_wp_error( $editor ) ) {
    138138                                $editor->set_quality( 100 );
    139139
     140                                // Get image metadata
     141                                add_filter( 'wp_read_image_metadata', array( __CLASS__, '_metadata_get_orientation' ), 10, 3 );
     142                                $meta = wp_read_image_metadata( $file );
     143                                remove_filter( 'wp_read_image_metadata', array( __CLASS__, '_metadata_get_orientation' ), 10, 3 );
     144
     145                                // Rotate the image for mobile devices
     146                                if ( wp_is_mobile() ) {
     147                                        if( ! empty( $meta['Orientation'] ) ) {
     148                                                switch( $meta['Orientation'] ) {
     149                                                        case 8:
     150                                                                $editor->rotate( 90 );
     151                                                                break;
     152                                                        case 3:
     153                                                                $editor->rotate( 180 );
     154                                                                break;
     155                                                        case 6:
     156                                                                $editor->rotate( -90 );
     157                                                                break;
     158                                                }
     159                                        }
     160                                }
     161
    140162                                $resized = $editor->resize( bp_core_avatar_original_max_width(), bp_core_avatar_original_max_width(), false );
    141163                                if ( ! is_wp_error( $resized ) ) {
    142164                                        $thumb = $editor->save( $editor->generate_filename() );
    class BP_Attachment_Avatar extends BP_Attachment { 
    418440                 */
    419441                return apply_filters( 'bp_attachment_avatar_script_data', $script_data, $object );
    420442        }
     443
     444        /**
     445         * Get and set the orientation for an image.
     446         *
     447         * This filter is used primarily to support WP 3.8.0 - 3.9.x.
     448         *
     449         * @todo Temporary and subject to removal after BuddyPress supports WP 4.0+.
     450         *
     451         * @param  array  $meta            Image meta data.
     452         * @param  string $file            Path to image file.
     453         * @param  int    $sourceImageType Type of image.
     454         * @return array
     455         */
     456        public static function _metadata_get_orientation( $meta = array(), $file = '', $sourceImageType = 0 ) {
     457                // WP 4.0+ is good!
     458                if ( true === version_compare( bp_get_major_wp_version(), '4.0', '>=' ) ) {
     459                        return $meta;
     460                }
     461
     462                // The things we do for backward compatibility...
     463                if ( is_callable( 'exif_read_data' ) && in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) {
     464                        $exif = @exif_read_data( $file );
     465
     466                        if ( ! empty( $exif['Orientation'] ) ) {
     467                                $meta['orientation'] = $exif['Orientation'];
     468                        }
     469                }
     470
     471                return $meta;
     472        }
    421473}