MyBB Community Forums

Full Version: Apply a random avatar to every user on the board?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I know it's possible to assign an image to group, but I want to apply a random avatar to every user on the board. Is this possible? I don't want it to change every time they login or post... Just apply a random image to every user within a given group of users...Preferably leaving alone the users who already have an avatar, or to users as they register.


I found this http://mods.mybb.com/view/mydevel-generate which is CLOSE to what I need, but it only applies when creating new random users through the plugin.

This is close as well http://mods.mybb.com/view/default-avatar but it frustratingly only allows a single image as opposed to randomly selecting one from a given directory. Also looks like it would apply only to new signups, not existing users... Which wouldn't be so bad... The main roadblock with this is not allowing a random.

Here's another. Close but no cigar. Sets a default avatar by gender. http://mods.mybb.com/view/default-avatar-by-gender

Yet another. This looks damn close, automatically assigns an avatar at signup, but not at random from a directory... http://mods.mybb.com/view/default-profile-for-1-6

Really surprised no plugin for this yet. To apply a random avatar to users upon registration or to groups of existing users.

Okay, I've found this random image plucker code. Rated high on stack exchange.

$imagesDir = 'images/tips/';

$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);

$randomImage = $images[array_rand($images)];

But not sure where/how to apply it. I'd like to be able to apply it to everyone on the board who doesn't currently have an avatar and/or apply it to people as they register...

Any ideas?
Hmmm... didn't think it would be such a difficult challenge to apply a random Avatar at signup.... especially with the code already there for plucking. Mod, possible to move this to Plugins/Mods?
@Gizbeat :
You can try including your random image path generator code in:
inc\datahandlers\user.php

and replace this two lines at near line no. 998 / 999:

"avatar" => $db->escape_string($user['avatar']),
"avatartype" => $db->escape_string($user['avatartype']),

to

"avatar" => $randomImage,
"avatardimensions" => '100|100',
"avatartype" => 'gallery'

I hope this will work.
maybe this will work. try it.
(2013-06-17, 02:35 PM)McCoist Wrote: [ -> ]http://mods.mybb.com/view/default-avatar

Enjoy.
Well, this sets only single avatar. Not random.

(2013-06-17, 02:45 PM)effone Wrote: [ -> ]@Gizbeat :
You can try including your random image path generator code in:
inc\datahandlers\user.php

and replace this two lines at near line no. 998 / 999:

"avatar" => $db->escape_string($user['avatar']),
"avatartype" => $db->escape_string($user['avatartype']),

to

"avatar" => $randomImage,
"avatardimensions" => '100|100',
"avatartype" => 'gallery'

I hope this will work.

I will possibly give it a go in the future. Will this set it just once? Will it apply to all users or just new users? Where to put the randomization code?

Regardless, I found a plugin from Mr. Yaldaram and it works as advertised http://yaldaram.com/thread-645.html

(2013-06-17, 03:18 PM)snippets69 Wrote: [ -> ]maybe this will work. try it.

Maybe in the future.
Well, this is for the new registerds only.
It will set random avatar from the directory to each user upon registration, but what the avatar is set will remain unless being changed manually.