|
Page 1 of 1
|
Mighty Gorgon 
Luca Libralato
Joined: August 2006
Posts: 7192
Location:  Borgo San Michele
|
 Random Avatar
I have created for a friend a very simple script which creates a random avatar to be used on any forum/blog software.
All you have to do is the following:
- Create a folder called avatars in your site root with all the PNG images you want to use (I have forced this script to process PNG). Of course you can use any other name or path, but then you will need to change other references to it accordingly.
- Rename all the images with a consecutive number with leading zeroes (000001.png, 000002.png, 000003.png and so on...), all files names should be 6 chars long. Then change the number of images $random_avatar_n = 699; to reflect the total amount.
- Create a new file called avatar.php, paste in it the code from the box here below and then copy the file it in the folder you just created with all images (i.e.: yoursite.com/avatars/avatar.php).
<? $random_avatar_n = 699; if (function_exists(mt_rand)) { $rand = mt_rand(1, $random_avatar_n); } else { $rand = rand(1, $random_avatar_n); } header('Content-type: image/png'); header('Cache-Control: no-store, no-cache, no-transform, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0, max-age=0', false); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Pragma: no-cache'); echo file_get_contents(str_pad($rand, 6, '0', STR_PAD_LEFT) . '.png'); ?>
- Alter your .htacces (in your root) by adding this line (change path and filenames accordingly):
Redirect /avatar.png http://www.yoursite.com/avatars/avatar.php
- Go in your browser and just recall the avatar:
Redirect /avatar.png http://www.yoursite.com/avatar.png
If you did everything correctly you should have something like this:
http://www.mightygorgon.com/avatar.png
Once the page is loaded, just refresh it and the image should change...
I hope you like this script!
P.S.: I forgot to mention that you should carefully choose your images to not be too wide...
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#1 Tue 25 May, 2010 20:45 |
|
Sponsors

|
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.
|
|
nothere
Joined: May 2010
Posts: 45
|
 Re: Random Avatar
Hi,
Thank you for the script. I think it's really cool.
I have a question. Do I place the script in the overall_footer or overall_header ; neither? In the meantime, I'll mess around with this in WAMP.
Thanks again,
Dan
|
#2 Sat 07 May, 2011 21:12 |
|
Joshua203 
Joshua 203
Dutch A Go Go

Joined: August 2008
Posts: 1754
Location:  Earth, Europe, the Netherlands, Rotterdam
|
 Re: Random Avatar
Hi nothere,
If I understand MG's post correctly... neither.. according to point 3 you create a new file called avatar.php for the script
____________ www.DutchaGoGo.com (development/under construction ...Forever?¿?)
|
#3 Fri 13 May, 2011 09:23 |
|
Mighty Gorgon 
Luca Libralato
Joined: August 2006
Posts: 7192
Location:  Borgo San Michele
|
 Re: Random Avatar
Instructions were not clear... I have adjusted the first post... let me know if everything is clear now.
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#4 Sun 15 May, 2011 12:09 |
|
nothere
Joined: May 2010
Posts: 45
|
 Re: Random Avatar
Hello,
I apologize for the extremely late replay
However, I just wanted to let you know that the instructions worked very well.
And thank you so much for such a wonderful script.
|
#5 Thu 14 Jul, 2011 07:18 |
|
Jimbo75 
Joined: September 2011
Posts: 1
|
 Re: Random Avatar
Can you clarify - sorry, I might be being a bit slow on the uptake here as I've only done a very limited amount of php before.
Point 2 has: "Then change the number of images $random_avatar_n = 699; to reflect the total amount."
So, if I have 5 avatar images: 000001.png, 000002.png, 000003.png, 000004.png, 000005.png
Would I change $random_avatar_n = 699 to:
$random_avatar_n = 05, or
$random_avatar_n = 5
|
#6 Fri 02 Sep, 2011 23:45 |
|
Joshua203 
Joshua 203
Dutch A Go Go

Joined: August 2008
Posts: 1754
Location:  Earth, Europe, the Netherlands, Rotterdam
|
 Re: Random Avatar
Hi Jimbo,
5 would be a safe bet I guess
____________ www.DutchaGoGo.com (development/under construction ...Forever?¿?)
|
#7 Sat 03 Sep, 2011 11:38 |
|
cassiopeiastars9 
Theo Sharon
Joined: October 2011
Posts: 3
Location:  Bandung
|
 Re: Random Avatar
Hi, MG....
do you have any specific max pixel size or kb size perhaps.... so the image still can be loaded?
thanks anyway
|
#8 Sat 22 Oct, 2011 06:28 |
|
Joshua203 
Joshua 203
Dutch A Go Go

Joined: August 2008
Posts: 1754
Location:  Earth, Europe, the Netherlands, Rotterdam
|
 Re: Random Avatar
Since you are the one in charge of which images are uploaded it would be easiest to just make sure they do not exceed the smallest limit of where you will use them.
Maybe even shrink them or blow them up a bit before uploading them to make them all the same size
____________ www.DutchaGoGo.com (development/under construction ...Forever?¿?)
|
#9 Sat 22 Oct, 2011 07:27 |
|
|
Page 1 of 1
|
Was this topic useful?
Was this topic useful?
Link this topic |
URL |
|
BBCode |
|
HTML |
|
You cannot post new topics You cannot reply to topics You cannot edit your posts You cannot delete your posts You cannot vote in polls You cannot attach files You can download files You cannot post calendar events
|
|
|
|