Reply to topic  [ 5 posts ] 
Random Avatars - how it’s done 
Author Message
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12203
Reply with quote
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


Fri Apr 24, 2009 10:02 am
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:14 pm
Posts: 5662
Location: Scotland
Reply with quote
Does this eccentric trick work on windows XP or do I need a mac? no server required?

_________________
Image


Mon Jan 14, 2013 12:27 pm
Profile
Spends far too much time on here
User avatar

Joined: Thu Apr 23, 2009 6:44 pm
Posts: 4141
Location: Exeter
Reply with quote
brataccas wrote:
Does this eccentric trick work on windows XP or do I need a mac? no server required?


It's something the Masons do for you if you ask them nicely.

_________________
"The woman is a riddle inside a mystery wrapped in an enigma I've had sex with."


Mon Jan 14, 2013 12:39 pm
Profile WWW
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
brataccas wrote:
Does this eccentric trick work on windows XP or do I need a mac? no server required?

It's done server-side so what type of PC you use doesn't really come in to it.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Mon Jan 14, 2013 12:50 pm
Profile
What's a life?
User avatar

Joined: Thu Apr 23, 2009 6:27 pm
Posts: 12203
Reply with quote
Yup - all on the server side driven. It’s a Linux machine, but what it does - stream the data from a randomly chosen file to your browser could be done on a Windows IIS server if you knew someone handy with ASP. I expect even Windows NT 2000 could do this. ;)

_________________
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


Mon Jan 14, 2013 12:59 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: cloaked_wolf and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.