BuddyDev

Search

Cover Image cropping Function

  • Participant
    Level: Initiated
    Posts: 8
    stjames on #33089

    I saw that topics on here. I am going to add cover image cropping feature in buddypress.
    I added code on bp-custom.php

    <?php

    if ( !defined( ‘BP_AVATAR_THUMB_WIDTH’ ) )
    define( ‘BP_AVATAR_THUMB_WIDTH’, 120 ); //change this with your desired thumb width

    if ( !defined( ‘BP_AVATAR_THUMB_HEIGHT’ ) )
    define( ‘BP_AVATAR_THUMB_HEIGHT’, 120 ); //change this with your desired thumb height

    if ( !defined( ‘BP_AVATAR_FULL_WIDTH’ ) )
    define( ‘BP_AVATAR_FULL_WIDTH’, 580 ); //change this with your desired full size,weel I changed it to 260 :)

    if ( !defined( ‘BP_AVATAR_FULL_HEIGHT’ ) )
    define( ‘BP_AVATAR_FULL_HEIGHT’, 580 ); //change this to default height for full avatar

    // this is cover image cropping function
    function buddydev_enable_crop_for_cover_image( $args ) {
    $args[‘crop’] = true;

    return $args;
    }
    add_filter( ‘bp_after_attachment_cover_image_edit_image_parse_args’, ‘buddydev_enable_crop_for_cover_image’ );

    function cm_xprofile_cover_image( $settings = array() ) {
    $settings[‘width’] = 1200;
    $settings[‘height’] = 400;

    return $settings;
    }
    add_filter( ‘bp_before_xprofile_cover_image_settings_parse_args’, ‘cm_xprofile_cover_image’, 10, 1 );
    add_filter( ‘bp_before_groups_cover_image_settings_parse_args’, ‘cm_xprofile_cover_image’, 10, 1 );

    ?>

    But I can’t crop background cover image in my site.
    let me know that.

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #33093

    Hi James,
    Thank you for opening a new topic.

    You can remove other code and use the following code to force crop

    
    function buddydev_enable_crop_for_cover_image( $args ) {
    	$args['crop'] = true;
    
    	return $args;
    }
    add_filter( 'bp_after_attachment_cover_image_edit_image_parse_args', 'buddydev_enable_crop_for_cover_image' );
    
    

    This will not show any user interface. What it does is forces BuddyPress to crop images to the registered dimension instead of resizing the image.

    In case you want to set a custom height/width for the cover and not use the default by BuddyPress, you can use the following code too

    
    
    function bd_set_xprofile_cover_image_dimension( $settings = array() ) {
    	$settings['width'] = 800;
    	$settings['height'] = 400;
    
    	return $settings;
    }
    add_filter( 'bp_before_members_cover_image_settings_parse_args', 'bd_set_xprofile_cover_image_dimension', 100, 1 );
    add_filter( 'bp_before_groups_cover_image_settings_parse_args', 'bd_set_xprofile_cover_image_dimension', 100, 1 );
    
    

    Please change the width/height as needed.

    And lastly, you may want to remove the default notice by BuddyPress. to do that, Please add the following code.

    
    
    add_action( 'bp_loaded', function () {
    	remove_action( 'wp_ajax_bp_cover_image_upload', 'bp_attachments_cover_image_ajax_upload' );
    } );
    
    

    Please try uploading an image and cover and check if the image is cropped to correct dimension or not?

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 8
    stjames on #33099
    This reply has been marked as private.
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #33102
    This reply has been marked as private.
  • Participant
    Level: Initiated
    Posts: 8
    stjames on #33106
    This reply has been marked as private.

You must be logged in to reply to this topic.

This topic is: not resolved