| |
The random avatar and image how-to
Retriever II |
|

Catalyst
![Host Badge [H]](https://archive.mfgg.net/html/badges/host.gif) ![Big Help Badge [*]](https://archive.mfgg.net/html/badges/bighelp.gif) ![Ultra Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/uhappyheart.gif) ![Super Submitter Badge [*]](https://archive.mfgg.net/html/badges/submissions.gif) ![Sprite Comp Winner Badge (2) [*]](https://archive.mfgg.net/html/badges/scg2.gif)
![Sprite Comp Top 5 Badge (2) [*]](https://archive.mfgg.net/html/badges/sct2.gif) ![MFGG Awards 2004 Winner [*]](https://archive.mfgg.net/html/badges/award04.gif) ![MFGG Awards 2005 Winner [*]](https://archive.mfgg.net/html/badges/award05.gif) ![MFGG Awards 2006 Winner [*]](https://archive.mfgg.net/html/badges/award06.gif) ![MFGG Awards 2007 Winner [*]](https://archive.mfgg.net/html/badges/award07.gif)

Group: Members
Posts: 18290
Member No.: 52
Joined: 13-October 03
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
I get asked this more than anything else, and some of the scripts other people are using are missing cache directives, so I'm posting my script and instructions What you needHosting that supports PHP and .htaccess files. The .htaccess support is necessary for avatars because the board won't let you use anything with a .php extention. I think Bytehost meets this criteria, after seeing Kaepora's avatar. After having a chance to use bytehost, I can't reccomend it for any hotlinking purposes, even though it worked otherwise. The PHP script: Copy the code into a file called avatar.jpg (or avatar.gif, or avatar.png - what's important is the board accepts the extention as a valid image extention) | CODE | <?php $files = array("1.gif","2.gif","3.gif","4.gif","5.gif","6.gif","7.gif","8.gif","9.gif");
srand((double)microtime()*1000000); $key = array_rand($files);
$img = $files[$key]; $img_part = explode(".", $img); $ext = array_pop($img_part);
header("Cache-Control: no-store, no-cache, must-revalidate"); header("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); header("Pragma: no-cache"); header("Content-type: image/$ext");
$bytes = file_get_contents($img); echo $bytes; ?> |
The .htaccess file: Copy the code into a file called .htaccess. If Windows won't let you use this filename - upload it under another filename, and rename it in your FTP program.
| CODE | | AddType application/x-httpd-php .jpg |
How to use it The two files should be uploaded to the same directory on your host. All the image files you want to use in the image should also be put in the same directory. The array in the PHP file should be changed to include the names of the images you upload. You can have as many or as few images in the array as you like, just surrounded in quotes and separated by commas.
The ".jpg" in the .htaccess file should be changed to whatever extention you saved the php file as. If you saved the script as avatar.png, then your .htaccess file should contain .png instead of .jpg. As a general rule, the extention you chose does not have to be the same extention as the images you use.
For those of you allready using random image scripts but find that the images aren't as random as you would like - pay attention to the first 3 header lines. These are necessary to make your image change each time someone sees them. Without them, your browser will likely store the image once and continue to display that until your cache clears.
FAQ Q: Do all my images have to be the same type? A: No - you can mix gifs and pngs and jpgs in your file list and it will all probably work. If you want to be absolutely sure, then make your images the same type.
Q: Do all my images have to be the same size? A: No - They can be any size you like. They can also have different widths and heights and the script won't care. What you do need to look out for is constraints where you use them. Some boards will force you to set a single width and height for your avatar. The safest thing to do is give your images the same dimentions.
Q: Will my avatar work if it gets stored on the forum? A: No. In vBulletins (possibly changed in recent versions), even if you enter the URL to your avatar, the board will capture the output of your avatar and save it locally on the board's server. When this happens, your avatar will not be random. When the board displays your avatar, it must point to your host, not try and save a copy. Likewise, if you try and upload your avatar to a forum, it won't work at all.
Q: Do I have to name my files 1.gif, 2.gif ... ? A: The files can be named anything you like. If you have 3 files named 'red.gif', 'blue.gif', and 'yellow.png', then the $files = line in the script gets changed to: $files = array("red.gif","blue.gif","yellow.png"); The array is simply a list, and you could put only one image in, or over a thousand if you had the patience to. Just follow the format.
Q: But my files have double quotes in the name A: I lied, there is a constraint in file names. You can either rename your file to something without double quotes, or when you enter the name into the list, put a single backslash ( \ ) in front of any double quotes in the name. This shouldn't be a problem though, because Windows will never let you name your file with double quotes anyway.
Q: I tried to save the script as avatar.gif in notepad, but the file still came out as avatar.txt A: If file extentions are hidden in Windows, it will silently name your file avatar.gif.txt. You'll have to go into Tools->Folder Options, click the View Tab, and uncheck "Hide extentions of known file types". Then you can rename your file to avatar.gif. Alternatively, you can upload it as it is, and change the name in your FTP program, which is less likely to be fooled.
--------------------
 
|
|
|
Xgoff |
|

<):|
![Super Happy Heart Badge [*]](https://archive.mfgg.net/html/badges/shappyheart.gif) ![Sprite Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/scg1.gif) ![Drawing Comp Winner Badge (1) [*]](https://archive.mfgg.net/html/badges/dcg1.gif) ![Drawing Comp Runner Up Badge (1) [*]](https://archive.mfgg.net/html/badges/dcr1.gif) ![MFGG Awards 2006 Winner [*]](https://archive.mfgg.net/html/badges/award06.gif)
![MFGG Awards 2007 Winner [*]](https://archive.mfgg.net/html/badges/award07.gif) ![Forum Event Badge [*]](https://archive.mfgg.net/html/badges/event.gif)

Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03
Status: (0d)
![[--]](style_images/mfgg2_skin/warn_nosuspend.gif)

|
| QUOTE | Q: Do all my images have to be the same type? A: No - you can mix gifs and pngs and jpgs in your file list and it will all probably work. If you want to be absolutely sure, then make your images the same type. |
I was too lazy to convert some of mine but I just renamed the extensions anyway just to be safe
| QUOTE | Q: Do all my images have to be the same size? A: No - They can be any size you like. They can also have different widths and heights and the script won't care. What you do need to look out for is constraints where you use them. Some boards will force you to set a single width and height for your avatar. Others (such as MFGG) do not have this restraint. |
apparently that wasn't/isn't the case with Ryo's avatars since I had to manually resize all 54 of them so they'd quit looking all ****ed up
--------------------
 DISCLAIMER: by sending me (xgoff) a private message, you agree to the directives and their terms specified henceforth: DIRECTIVE 1 (APPLE): i may or may not reply promptly or at all; and there are no guarantees to the usefulness of the reply. i may not acknowledge whether i have even received your private message DIRECTIVE 2 (CHILE CON CARNE): as per my view, "private" applies only to the initial transaction, and the material of your message may or may not be made public at my discretion; as this will more than likely be a post in the CCC or IRC, you may not be able to view it DIRECTIVE 3 (FEATHER DUSTER): you must address me (xgoff) as "Sir Master Xgofficus his Highest and Most Awesome the Third"; failure to comply with this term may invoke one or both of the above directives, and i will leave a burning bag of **** on your doorstep DIRECTIVE 4 (BOOTSTRAP): if you have read this disclaimer, please private message me promptly, in compliance with the above terms, so i can ensure you are capable of following directions you idiot this concludes the test of the emergency disclaimer system, your scheduled programming will now continue. satisfaction guaranteed, and 100% cash back available under certain circumstances; restrictions may or may not apply within your place of residence NOTICE: these directives and their terms may change at any time, without notice; as a private message transaction to myself assumes an understanding and full compliance of the above, you should ensure you are fully aware of the above terms at any point before sending a private message; any message received is assumed to have been sent in compliance with the above| QUOTE | (5:25:58 PM) Mikau: xgoff (5:26:00 PM) Mikau: guess what (5:26:04 PM) Xgoff: chicken butt (5:26:09 PM) Mikau: **** you |
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
[ Script Execution time: 0.0714 ] [ 14 queries used ] [ GZIP Enabled ] [ Server Load: 0.81 ]
| |