MyBB Community Forums

Full Version: Randomize Avatar
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I want to randomize my avatar, but I can't seem to get it to work. I already have a php script on my website which returns a random url string. This is the script:

<pre>
<?php

$images[] = 'http://...avatar1.png';
$images[] = 'http://...avatar2.png';


srand ((double) microtime() * 1000000);
$random_number = rand(0,count($images)-1);
echo ($images[$random_number]);

?>
</pre>

(I had to shorten the urls for this message board because they were too long)

When I load my the page - it shows a text string of one of the urls.

But when I paste the link of my page into the 'Avatar URL:' field, it says the url is invalid. I was hoping that by returning the url, my avatar url can pretty much be randomized.

How can I get my avatar to show a random image? Or perhaps I'm doing this entirely wrong?
The avatar URL expects a graphical file (gif, png, jpg, etc) at the other end, not an HTML file with javascript.

what might work is create a simple PHP file (avatar.php) which randomly slurps one of your avatars and outputs it with the proper Content-type header. Now set your avatar url to point to avatar.php .
laie_techie Wrote:what might work is create a simple PHP file (avatar.php) which randomly slurps one of your avatars and outputs it with the proper Content-type header. Now set your avatar url to point to avatar.php .

yep. That's what dennis does.

Just set the content type header to the MIME type of the image.
Thanks for the help all, my avatar can now be randomized - yay! ^_^. Though I've noticed that it sometimes gets squished up, but I know that I am definitely under the avatar size restrictions and that it loads fully on a clear page - is there a way to fix this?
Oh and I forgot to add that this is the code I've got on my page so far.
<?php

header("Content-type: image/png");

$top = 3;
// Counts the number of signatures

$sig_id = rand(0, $top);
// Picks out a random signature

readfile("ava".$sig_id.".png");
// Outputs the random signature
?>
[/php]
Though strangely, my images end up getting squished on the forum but not my website. Is there fix/tweak for this? Thanks.