Icy Phoenix

     
 



Post new topic  Reply to topic 
Page 1 of 1
 
 
Reply with quote Download Post 
Post 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:
  1. 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.
  2. 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.
  3. 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).
    Code: (avatar.php) [Download] [Hide] [Select]
    <?
    $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');
    ?>

  4. Alter your .htacces (in your root) by adding this line (change path and filenames accordingly):
    Code: [Download] [Hide] [Select]
    Redirect /avatar.png http://www.yoursite.com/avatars/avatar.php

  5. Go in your browser and just recall the avatar:
    Code: [Download] [Hide] [Select]
    Redirect /avatar.png http://www.yoursite.com/avatar.png


If you did everything correctly you should have something like this:
Code: [Download] [Hide] [Select]
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
 
Mighty Gorgon - View user's profileSend private messageVisit poster's websitePersonal Gallery 
Back to topPage bottom
Thanks for the useful Topic Mighty Gorgon:
TheSteffen (03 June), rixard (20 March), nothere (07 May), Joshua203 (13 May), spydie (15 May) 
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.

Support us
 
Reply with quote Download Post 
Post 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
 



 
nothere - View user's profileSend private message 
Back to topPage bottom
Reply with quote Download Post 
Post 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?¿?)
 
Joshua203 - View user's profileSend private messageVisit poster's websitePersonal Gallery 
Back to topPage bottom
Reply with quote Download Post 
Post 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
 
Mighty Gorgon - View user's profileSend private messageVisit poster's websitePersonal Gallery 
Back to topPage bottom
Reply with quote Download Post 
Post 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.
 



 
nothere - View user's profileSend private message 
Back to topPage bottom
Reply with quote Download Post 
Post 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
 



 
Jimbo75 - View user's profileSend private message 
Back to topPage bottom
Reply with quote Download Post 
Post Re: Random Avatar 
 
Hi Jimbo,

5 would be a safe bet I guess
 




____________
www.DutchaGoGo.com (development/under construction ...Forever?¿?)
 
Joshua203 - View user's profileSend private messageVisit poster's websitePersonal Gallery 
Back to topPage bottom
Reply with quote Download Post 
Post 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      

    
 



 
cassiopeiastars9 - View user's profileSend private message 
Back to topPage bottom
Reply with quote Download Post 
Post 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?¿?)
 
Joshua203 - View user's profileSend private messageVisit poster's websitePersonal Gallery 
Back to topPage bottom
Post new topic  Reply to topic  Page 1 of 1
 


Display posts from previous:    

HideWas this topic useful?

Link this topic
URL
BBCode
HTML




 
Permissions List
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


  

 

cron