Powered by Invision Power Board

 
    Reply to this topicStart new topicStart Poll

> The random avatar and image how-to
United States
Retriever II
Posted: Apr 19 2006, 03:38 PM
Quote Post


Catalyst
[H][*][*][*][*]
[*][*][*][*][*]


Group Icon
Group: Members
Posts: 18290
Member No.: 52
Joined: 13-October 03

Status: (0d) [--]


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 need
Hosting 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.


--------------------

PMEmail PosterUsers WebsiteICQAOLMSN
Top
Unspecified
GutsMan
Posted: Apr 19 2006, 03:41 PM
Quote Post


Standard Member
[*][*][*]

Group Icon
Group: Members
Posts: 13754
Member No.: 534
Joined: 2-August 04

Status: (0d) [--]


woohoo i wanna try this


--------------------
user posted image

user posted image

al rato MFGG
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Xgoff
Posted: Apr 19 2006, 04:19 PM
Quote Post


<):|
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 52341
Member No.: 24
Joined: 13-October 03

Status: (0d) [--]


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


--------------------

This post may contain original research or unverified claims.
Please disregard the above information and contact an administrator.

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
PMEmail PosterUsers WebsiteAOLMSN
Top
United States
Retriever II
Posted: Apr 19 2006, 04:22 PM
Quote Post


Catalyst
[H][*][*][*][*]
[*][*][*][*][*]


Group Icon
Group: Members
Posts: 18290
Member No.: 52
Joined: 13-October 03

Status: (0d) [--]


I was pretty sure I changed the size requirements for Klobber. Maybe not.

Oh and changing the extention without converting is a bad idea. Better to leave it as its original extention so the appropriate MIME type gets sent.


--------------------

PMEmail PosterUsers WebsiteICQAOLMSN
Top
South Africa
Tri
Posted: Apr 19 2006, 04:40 PM
Quote Post


Courtesy of DJ Elly. (lol jsr)
[M][*][*][*][*]
[*][*][*]

Group Icon
Group: Moderators
Posts: 11832
Member No.: 836
Joined: 17-February 05

Status: (0d) [--]


< Works perfect no?


--------------------
PMEmail PosterAOLMSN
Top
United States
Mecha
Posted: Apr 19 2006, 04:40 PM
Quote Post


I DRIVE REALLY SLOW IN THE ULTRA-FAST LANE
[*][*][*][*][*]
[*][*]

Group Icon
Group: Members
Posts: 16224
Member No.: 1020
Joined: 7-May 05

Status: (0d) [--]


Thanks biggrin.gif
I'm lovin' it~


--------------------
Attacks              3
user posted imageuser posted imageuser posted image
PMEmail PosterUsers WebsiteIntegrity Messenger IMAOLMSN
Top
United States
Retriever II
Posted: Apr 19 2006, 04:59 PM
Quote Post


Catalyst
[H][*][*][*][*]
[*][*][*][*][*]


Group Icon
Group: Members
Posts: 18290
Member No.: 52
Joined: 13-October 03

Status: (0d) [--]


QUOTE (Yoshimuro @ Apr 19 2006, 05:40 PM)
< Works perfect no?

I don't think Ripway works for this purpose. It doesn't support the .htaccess file.


--------------------

PMEmail PosterUsers WebsiteICQAOLMSN
Top
United States
Retriever II
Posted: Apr 23 2006, 12:05 AM
Quote Post


Catalyst
[H][*][*][*][*]
[*][*][*][*][*]


Group Icon
Group: Members
Posts: 18290
Member No.: 52
Joined: 13-October 03

Status: (0d) [--]


Turns out a standard PHP function doesn't work right on Bytehost, so I've changed the script to use a different output method. Requires PHP 4.3.0 or greater.


--------------------

PMEmail PosterUsers WebsiteICQAOLMSN
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

  Topic Options Topic Options Reply to this topicStart new topicStart Poll

 




[ Script Execution time: 0.0831 ]   [ 14 queries used ]   [ GZIP Enabled ]   [ Server Load: 2.29 ]