Skip to:
Content

BuddyPress.org

Changeset 10206


Ignore:
Timestamp:
10/07/2015 04:47:14 PM (9 years ago)
Author:
imath
Message:

Avatar UI: make sure to display the full content of the image during the cropping step.

When a user uploads an image to set his avatar, we are saving a temporary version of it resized using the bp_core_avatar_original_max_width() dimension (by default 450px). This resized image will be output to the user so that he can edit it during the cropping step. Once the avatar is saved, we are deleting this temporary image.

Sometimes, the Avatar UI width is smaller than this resized version of the image and as a result the image is truncated on its right side (this mainly happens on mobile devices). To avoid this, the Avatar UI is now informing about its available width and if it is smaller than bp_core_avatar_original_max_width(). This available width will be used to generate the tempory image so that the full content of the image will be displayed to the user when cropping his avatar.

Fixes #6586

Location:
trunk/src/bp-core
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-avatars.php

    r10151 r10206  
    821821    }
    822822
     823    // The Avatar UI available width
     824    $ui_available_width = 0;
     825
     826    // Try to set the ui_available_width using the avatar_admin global
     827    if ( isset( $bp->avatar_admin->ui_available_width ) ) {
     828        $ui_available_width = $bp->avatar_admin->ui_available_width;
     829    }
     830
    823831    // Maybe resize.
    824     $bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'] );
     832    $bp->avatar_admin->resized = $avatar_attachment->shrink( $bp->avatar_admin->original['file'], $ui_available_width );
    825833    $bp->avatar_admin->image   = new stdClass();
    826834
     
    932940    if ( ! isset( $bp->avatar_admin ) ) {
    933941        $bp->avatar_admin = new stdClass();
     942    }
     943
     944    /**
     945     * The BuddyPress upload parameters is including the Avatar UI Available width,
     946     * add it to the avatar_admin global for a later use.
     947     */
     948    if ( isset( $bp_params['ui_available_width'] ) ) {
     949        $bp->avatar_admin->ui_available_width =  (int) $bp_params['ui_available_width'];
    934950    }
    935951
  • trunk/src/bp-core/classes/class-bp-attachment-avatar.php

    r10178 r10206  
    118118     *
    119119     * @since 2.3.0
     120     * @since 2.4.0 Add the $ui_available_width parameter, to inform about the Avatar UI width.
    120121     *
    121122     * @uses  bp_core_avatar_original_max_width()
     
    125126     * @return mixed
    126127     */
    127     public static function shrink( $file = '' ) {
     128    public static function shrink( $file = '', $ui_available_width = 0 ) {
    128129        // Get image size
    129130        $avatar_data = parent::get_image_data( $file );
     
    132133        $edit_args = array();
    133134
     135        // Defaults to the Avatar original max width constant.
     136        $original_max_width = bp_core_avatar_original_max_width();
     137
     138        // The ui_available_width is defined and it's smaller than the Avatar original max width
     139        if ( ! empty( $ui_available_width ) && $ui_available_width < $original_max_width ) {
     140            /**
     141             * In this case, to make sure the content of the image will be fully displayed
     142             * during the cropping step, let's use the Avatar UI Available width.
     143             */
     144            $original_max_width = $ui_available_width;
     145
     146            // $original_max_width has to be larger than the avatar's full width
     147            if ( $original_max_width < bp_core_avatar_full_width() ) {
     148                $original_max_width = bp_core_avatar_full_width();
     149            }
     150        }
     151
    134152        // Do we need to resize the image ?
    135         if ( isset( $avatar_data['width'] ) && $avatar_data['width'] > bp_core_avatar_original_max_width() ) {
     153        if ( isset( $avatar_data['width'] ) && $avatar_data['width'] > $original_max_width ) {
    136154            $edit_args = array(
    137                 'max_w' => bp_core_avatar_original_max_width(),
    138                 'max_h' => bp_core_avatar_original_max_width(),
     155                'max_w' => $original_max_width,
     156                'max_h' => $original_max_width,
    139157            );
    140158        }
  • trunk/src/bp-core/js/bp-plupload.js

    r10070 r10206  
    6161         */
    6262        this.uploader.bind( 'Init', function( uploader ) {
    63             var container = $( '#' + self.params.defaults.container ),
     63            var container    = $( '#' + self.params.defaults.container ),
    6464                drop_element = $( '#' + self.params.defaults.drop_element );
    6565
    6666            if ( 'html4' === uploader.runtime ) {
    6767                uploader.settings.multipart_params.html4 = true;
     68            }
     69
     70            /**
     71             * Avatars need to be cropped, by default we are using an original
     72             * max width of 450px, but there can be cases when this max width
     73             * is larger than the one of the Avatar UI (eg: on mobile). To avoid any
     74             * difficulties, we're adding a ui_available_width argument to the bp_params
     75             * object and set it according to the container width. This value will be
     76             * checked during the upload process to eventually adapt the resized avatar.
     77             */
     78            if ( 'bp_avatar_upload' ===  uploader.settings.multipart_params.action ) {
     79                 uploader.settings.multipart_params.bp_params.ui_available_width = container.width();
    6880            }
    6981
Note: See TracChangeset for help on using the changeset viewer.