Random Avatars - how it’s done

Just like it should be, discuss things here

Moderators: HeatherKay, saspro, Blue_Nowhere, timark_uk, l3v1ck

User avatar
paulzolo
I haven't seen my friends in so long
 
Posts: 6431
Joined: Thu Apr 23, 2009 6:27 pm

Random Avatars - how it’s done

Postby paulzolo » Fri Apr 24, 2009 10:02 am

I’ve copied this from the old forum, as people like to know.

Folk ask me from time to time how I get my avatar to change. I get stopped regularly in the street and asked that question. I laugh when people think I do it manually. I'm just too lazy to oblige you to this level.

I do, however, employ some server based trickery.

So, let’s take a call from one of our listeners.....
bally199 wrote:Paulzolo, tell us the secret!


bally199 is labouring under the delusion that there is some secret involved. He's also laughing. Poor fool. Must be the meths....

Well, bally199999, you can tell servers that files are to be treated in certain ways. A file ending in .gif or .jpg does not necessarily have to be an image.

You see, index.jpg is not really an image file.

In the case of the file for my avatar, it's a .php file. Instead of .php at the end of the file name, I use .jpg. This means the PHPBB and others accepts the URL of the file.

I use a .htaccess file to tell the server to treat the file as a .php file (which is what it is anyway). To not do this, the server will think it's a graphic and will serve up the file with all the appropriate headers. We don’t want this - yet. The server seems index.gif, and runs it as php.

Now, bally19999999999999999999, the fun can start.

The php scans the folder, looks for all images therein (apart from itself) and picks one at random. It then throws the correct headers (so the server and your browser treat the file as a graphic) and the bytestream (the actual numbers which make up the image you want to show) at the browser.

The result is a random image:
http://www.worldofpaul.com/avatars2/index.jpg <-- click the URL.

If you refresh the browser, the image will change. But it's still index.jpg.

I hope that bally199999999999 and others find this answer enlightening and useful.

Does this help?
All the best,
Paul
brataccas wrote:your posts are just combo chains of funny win

I’m on Twitter, tweeting away... My Photos Random Avatar Explanation
Image

Return to The Meeting Place

Who is online

Users browsing this forum: Linux_User and 1 guest