Skip to:
Content
Pages
Categories
Search
Top
Bottom

3rd Sized Avatar

  • @darqpony

    Participant

    Disclaimer: I know just enough to get me in trouble ( to whitescreen my site? LOL) I know to put some ‘things’ in some ‘places’ but I don’t know why. On the road to website optimization, gtmetrix.com told me to send ‘scaled’ images to my pages and one of the un-scaled cuprits? Avatars. Full and thumb avatars are being downsized to teeny tiny avatars. At this point, with only my five website users, it’s not such a big deal, but when I get miiiyyons of followers?!? (LOL *sarcasm*) Five long days later, trudging through many many website with the glimmer of hope tarnishing to dust, and while I’ve learned a lot, I’m gonna cheat now and ask for the answer… LOL At least I’ll understand the answer better? I hope? LOL

    So, on to the issue…

    I’m trying to get, and use a 3rd sized avatar. By copy-past-edit, I’ve been able to actually create that third size of avatar, cropped, which I call ‘tinythumb’. So in an individual user’s avatar folder, there are 3 avatars sized ‘full’, ‘thumb’ and ‘tinythumb’. Yaay, me!

    My issue is that I cannot figure out how to call it into action. I’ve used bp_member_avatar(‘type=tinythumb&width=20&height=20′) in the appropriate spot of my widgets and pages but it doesn’t show up unless I change the “type” from “full” to “tinythumb” down below. But then ALL my pics are being served from a “tinythumb” and upscaled all pixelated.

    On line 375 in bp-core-avatars.php, there is a phrase that says:

      ORIGINAL: $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’;

    If I put in ‘-bptinythumb’ in that line, I get the white screen of syntax error death. By trial and error, edit-upload-edit-reupload, it says there is an error with ‘:’ or the “;” or if I try to use a comma, “,”.

      ERROR: $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’ : ‘-bptinythumb’;
      ERROR: $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’, ‘-bpthumb’ , ‘-bptinythumb’;
      ERROR: $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’; ‘-bpthumb’ ; ‘-bptinythumb’;

    If I change the ( ‘full’ == $type ) to ( ‘tinythumb’ == $type ), I get a teeny tiny avatar blown up, blurry and pixilated so I know that it can ‘see’ the ‘tinythumb’ avatar, I just can’t get it into the second part of the phrase. Either somewhere it is telling wordpress or buddypress to only ‘look’ for two options OR, because I don’t know how to code (BIG understatement! LOL) I’m not putting it in the correct format.

    Also, I’m not sure if I haven’t explained to the code, the ‘–bp’ part of the ‘–bptinythumb’ so that might be the issue but I can’t tell because I don’t know where to tell it to do that.

    How do I get it to ‘see’ the ‘tinythumb’ avatar and use it? Is there an easier and better way?
    (Dear god make it so…:) ) Hopefully someone better than me will get to the heart of this and point me in the right direction. Thanks so much!

    http://delightfulhorse.com in case you want to see the site in question. If you see a white screen, it’s cuz I’m messing with stuff. Give it a minute and I’ll be re-uploading the original. Unless my internet goes out… (the horror!) LOL

Viewing 18 replies - 1 through 18 (of 18 total)
  • @modemlooper

    Moderator

    just use thumb and scale down

    @darqpony

    Participant

    That’s the easy way out and already being done by the theme. My goal here is two-fold. Gmetrix.com’s web optimization said I should serve already scaled images and as I search for the way to do that, it has now become a mission. I just want to know HOW! Scaling down a thumb isn’t the same as having that third size (I have it) and being able to use that third size (creates an error once called into action). I cannot figure out why I can’t get that third size to be used without an error. I figure once I learn the ‘why’, I will understand so much more.

    🙂

    @henrywright

    Moderator

    Hi @darqpony

    1. Thumbs

    define ( 'BP_AVATAR_THUMB_WIDTH', 20 );
    define ( 'BP_AVATAR_THUMB_HEIGHT', 20 );

    2. Full

    define ( 'BP_AVATAR_FULL_WIDTH', 150 );
    define ( 'BP_AVATAR_FULL_HEIGHT', 150 );

    3. Original

    define ( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 300 );

    4. File size

    define ( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $max_in_kb );

    Now, you can use bp_core_fetch_avatar to output either the thumb or the full size avatar. This doesn’t cover the original. You could write your own version of bp_core_fetch_avatar which will output the original as well. That’s if the original is saved. You’ll have to check that it is. I’m sure it will be but have never needed to use it so you might want to make sure.

    @modemlooper

    Moderator

    Henry, he wants a third size image.

    @henrywright

    Moderator

    I was thinking this?

    1st: The thumb size
    2nd: The full size
    3rd: The original size

    @darqpony

    Participant

    Yes, I already have the different various sizes of avatar. I have the Tinythumb, Thumb, and Full sizes. And I can change them to whatever width and height I’d like them to be. I could make miiiiyyyons of them if I so chose. Thumb1, Thumb2, Thumb3, etc. . . . Not the issue. I’m stuck in the calling of them to my themes widget. I can call only two of those sizes. If I change $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’; to add ‘-bptinythumb’, it defaults back to the default of full and bpfull or bpthumb. I can’t get it to USE bptinythumb in the theme. Or in actuality, to USE more than two, hence I need it to SEE the third size avatar.

    🙂

    And thanks so much for taking a look at this guys.

    PS: And I’m gonna check to see what bp_core_fetch_avatar does… maybe rewriting it will get me what I want. Maybe you guys know already how I should rewrite it? *Hint hint* LOL

    @darqpony

    Participant

    Yes, I already have the different various sizes of avatar. I have the Tinythumb, Thumb, and Full sizes. And I can change them to whatever width and height I’d like them to be. I could make miiiiyyyons of them if I so chose. Thumb1, Thumb2, Thumb3, etc. . . . Not the issue. I’m stuck in the calling of them to my themes widget. I can call only two of those sizes. If I change $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’; to add ‘-bptinythumb’, it defaults back to the default of full and bpfull or bpthumb. I can’t get it to USE bptinythumb in the theme. Or in actuality, to USE more than two, hence I need it to SEE the third size avatar.

    🙂

    And thanks so much for taking a look at this guys.

    @darqpony

    Participant

    Sorry about the double post… the first didn’t show up for a while so I rehit submit…

    Back to the issue:

    If I remove

      $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’;

    from my bp-core-avatars.php file, all my avatars revert back to my default avatar pic.

    @darqpony

    Participant

    The below is in bp-core-avatars.php file.

      /**
      * Look for uploaded avatar first. Use it if it exists.
      * Set the file names to search for, to select the full size
      * or thumbnail image.
      */
      $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’;
      $legacy_user_avatar_name = ( ‘full’ == $type ) ? ‘-avatar2’ : ‘-avatar1’;
      $legacy_group_avatar_name = ( ‘full’ == $type ) ? ‘-groupavatar-full’ : ‘-groupavatar-thumb’;

    On the line where it says $avatar_size, I need to be able to add for it to look for the ’-bptinythumb’ size ALSO. How do I do that?

    @henrywright

    Moderator

    You’d change $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb; to:

    if ($type == 'full' ) {
        $avatar_size = '-bpfull';
    } elseif ($type == 'thumb' ) {
        $avatar_size = '-bpthumb';
    } else {
        $avatar_size = '-bptinythumb';
    }

    But that approach wouldn’t be recommended because when you upgrade buddypress your changes will be lost.

    The tiny thumb will be the default avatar size. If you wanted to use the thumb or full versions then you’d need to pass thumb or full to bp_core_fetch_avatar

    @darqpony

    Participant

    Yes! that! Since I know so little about php coding, I didn’t know WHAT to do instead of the choice it gave me or where to look.

    1. I understand about the upgrade will overwrite thing. If I put this bit of code in my bpcustom.php file, will it override the original “$avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb;” or do I have to somehow negate that first in the bpcustom file?

    2. I have this in the bp_core_fetch_avatar:

    function bp_core_fetch_avatar( $args = '' ) {
    
    	// If avatars are disabled for the root site, obey that request and bail
    	if ( ! buddypress()->avatar->show_avatars )
    		return;
    
    	global $current_blog;
    
    	$bp = buddypress();
    
    	// Set a few default variables
    	$def_object = 'user';
    	$def_type   = 'thumb';
    	$def_class  = 'avatar';
    
    	// Set the default variables array
    	$params = wp_parse_args( $args, array(
    		'item_id'    => false,
    		'object'     => $def_object, // user/group/blog/custom type (if you use filters)
    		'type'       => $def_type,   // tinythumb, thumb or full
    		'avatar_dir' => false,       // Specify a custom avatar directory for your object
    		'width'      => false,       // Custom width (int)
    		'height'     => false,       // Custom height (int)
    		'class'      => $def_class,  // Custom <img> class (string)
    		'css_id'     => false,       // Custom <img> ID (string)
    		'alt'        => '',    	     // Custom <img> alt (string)
    		'email'      => false,       // Pass the user email (for gravatar) to prevent querying the DB for it
    		'no_grav'    => false,       // If there is no avatar found, return false instead of a grav?
    		'html'       => true,        // Wrap the return img URL in <img />
    		'title'      => ''           // Custom <img> title (string)
    	) );
    	extract( $params, EXTR_SKIP );
    

    Where do I ‘pass’ thumb or full to it? Or is it already there in this original since I haven’t changed anything yet?

    3. If I change the bp_core_fetch_avatar, do I have to somehow change the first 1.’s solution?

    4. Should I post this on the other site you found my question on? LOL (Hey, I gave it two days before trying a different site! But got the same guy answering… go figure… LOL)

    … and yes, it did use the tinythumb type and it did make the thumb sized avatar fuzzy. I have an avatar for that size. I want it to use it! LOL I want to use ALL my avatars!

    @henrywright

    Moderator

    So, with the code I suggested in place. You can output the 3 sized avatars on your site like this:

    Thumb size:

    $type = 'thumb';
    $width = 200;
    $height = 200;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'type' => $type, 'title' => $user_fullname ) );

    Full size:

    $type = 'full';
    $width = 500;
    $height = 500;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'type' => $type, 'title' => $user_fullname ) );

    Tiny thumb size:

    $width = 20;
    $height = 20;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'title' => $user_fullname ) );

    Note: It isn’t recommended to change core files in this way because you’ll lose the changes you made on each upgrade. But it’s what you asked for so… 🙂

    @darqpony

    Participant

    I”m still working on this. Getting a “Fatal error: Call to undefined function bp_get_loggedin_user_fullname” I don’t get to work on this as much as I’d like so bear with me… Life, ya know? 🙂

    And this is not necessarily what I ‘asked’ for… I don’t know enough to ‘ask’ for anything! LOL I was going to put the custom code in a custom file that wasn’t going to get overwritten upon upgrade. Does that not work? If you have a better way, please please please teach me! Or point me in the right direction?

    I’ve tried the code in both places, in the original and in the custom code and it still gave me an error so, there you go! 🙂

    @darqpony

    Participant

    Again, I ask, does anyone have a better way? I am getting the above Fatal Error, and I would still like to know if there is a better way of doing this without editing core files?

    @henrywright

    Moderator

    bp_get_loggedin_user_fullname() is a function defined in bp-members/bp-members-template.php – are you sure you have BuddyPress installed?

    @darqpony

    Participant

    LOL… yes I have buddypress installed.

    @henrywright

    Moderator

    Lol. I’m not sure why you’re getting the fatal error function not defined. It indicates the function doesn’t exist. We know it does exist as you have BP installed. So it’s strange!

    Maybe try replacing $user_fullname = bp_get_loggedin_user_fullname(); with $user_fullname = bp_loggedin_user_id();

    @henrywright

    Moderator

    That’ll output the member’s ID. Be interested to see if that throws a fatal error

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘3rd Sized Avatar’ is closed to new replies.
Skip to toolbar