MyBB Community Forums

Full Version: Help with custom avatars...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm putting together a Minecraft site, and in lieu of letting people upload avatars I was going to use the minotar.net avatar generator to make avatars based on their Minecraft username.

Basically how it works is it automatically generates an avatar based on how the characters face looks ingame. For instance for me, my Minecraft username is 'pixelbat'. If you go to this url you'll see how it works http://minotar.net/avatar/pixelbat/90.png It generates a 90x90 png of the characters face. You can change the username to anyone who plays the game. You can also change the 90 to any size up to 250.

I figured this would be relatively simple to implement using a required profile field upon registration to my site. Obviously I'm doing something wrong, or maybe this just isn't possible to do??

Here is what I got for my postbit_avatar template...

<a href="{$post['profilelink_plain']}"><img src="//minotar.net/avatar/{$profile_fields[fid4]}/90.png" alt="" {$avatar_width_height} /></a>

profile_fields[fid4] is the field I set up to be required upon registration.

If anyone has any ideas on how I can make this work, or maybe where I'm going wrong, I would gratefully appreciate the feedback. Thank you for your time.

Ok, so once I uploaded an avatar of my own, it started to display something. It's displaying the default avatar from minotar, which is linked to http://minotar.net/avatar//90.png. So it's totally omitting the {$profile_fields[fid4]}. I've tried both with and without ' marks around the fid4.

The second part to my issue seems that it requires a person to actually set an avatar before it will try to work. Could this be circumvented by setting a default for the avatar field within phpadmin?

I've also tried {$customfield['fid4']}, but no dice. I feel like this should work, but maybe I'm just overlooking something really little :|
Instead of {$profile_fields[fid4]} it should be {$post[fid4]}. This is why the name is blank in the generated URL, thus leading to the default avatar from minotar.

I just tested this on my local environment, and yes, for some reason, it doesn't work by default. The {postbit_avatar} template won't be embedded until someone changes to a custom avatar.
That did the trick. Just switched it to {$post[fid4]}. Much appreciated. Now just need to figure out how to circumvent requiring people to upload/set an avatar. I have a feeling setting a default in the dbase might work.

The more I think about this, the more I think I'm going about this the wrong way. Someone correct me if I'm wrong, but couldn't I just edit the usercp templates and remove the option to upload an avatar, then set up a custom postbit template that would just display the image based on the customfield input and then just call up the postbit where needed?
Yes, another way to do this is to circumvent the whole {$postbit_avatar} template.

To do this, you will lose some functionality, but it's easily remedied.

Edit your postbit template and look for the following lines:

<td class="post_avatar" width="1" style="{$post['avatar_padding']}">
	{$post['useravatar']}
</td>

Because you don't use the {$postbit_avatar} template, you lose the ability to use both {$post['avatar_padding']} and {$avatar_width_height}

Replacing {$avatar_width_height} isn't really a problem because you know exactly what the width and height are based on what URL you use for minotar.net's generator. In your case, you know it will be 90x90, so you can just explicitly type in the values.

As for {$post['avatar_padding']}, you must replace that bit of code yourself. If you look in the functions_post.php file, you'll see that the default is 10px of padding on the right. So, you'll end up with the following code:

<td class="post_avatar" width="1" style="padding-right: 10px;">
	<img src="//minotar.net/avatar/{$post[fid4]}/90.png" alt="" width="90" height="90" />
</td>

This works as the user's avatar whether or not they have set their own. However, this also does not allow them to use any other avatar besides this generated one (meaning that they cannot upload their own, no matter what). I'm pretty sure that's what you want based on what you stated above, I'm just remind you of that fact.
Darrell that was pretty much exactly what I was going for... the whole not letting them upload an avatar and use the generated ones.

I've got it set to display perfectly as an avatar in the Postbit...
[Image: jBL6ZIQ.jpg]

Now I'm trying to display this custom avatar elsewhere on the forums, like their profile page, and in the header as a block to identify themself when logged in... but it's not working. Using just this code as an example...
<img src="//minotar.net/avatar/{$post[fid4]}/90.png" alt="" width="90" height="90" />

It is outputting the url to the custom image only without the custom field data. So the image URL is "http://minotar.net/avatar//90.png". Is there something else I need to include to get that custom field data to work outside of the postbit template?

I'm starting to think what I'm trying to do is way out of my league. :\