PDA

View Full Version : Random Image Generator?


Ben@WEBProp
07-19-2004, 10:07 PM
http://www.ocremix.org/

I cannot tell how this was done, but look at the image in the top right of the banner (should be some sort of character). On the left navigation, click the link that says "about" in white letters on a dark bg...the character changes. Ok, so now click "about" again...the character changes again! Evertime you revisit a page, there is a new image that is cycled through...how is this done?

-Ben

raf
07-19-2004, 10:20 PM
i assume that this page is dynamically build using a server side language like php.

it's quite easy because all images are called

ocr4_mascotXX.jpg (where XX is a number).
So you have a small function to select a random number between 0 and lets say 100 and then you compose the imageadress.

As simple as


echo '<img src="/images/template/ocr4_mascot' . rand(1,99) . '.jpg" width="100" height="162" class="img-mascot" alt="" />';

Ben@WEBProp
07-19-2004, 11:35 PM
Thats pretty cool. Although I have no clue what-so-ever about php, I would like to learn it. Any quick tutorials you could shoot me to? (And yes...I will be searching by myself, I am not that lazy.) Also, could this same effect be achieved through something a little more simple, like JavaScript? Thanks raf.

-Ben

oracleguy
07-19-2004, 11:53 PM
You could do it with Javascript too but I'd personally use the PHP method, that way you don't have to worry about people with JS disabled.

raf
07-20-2004, 01:10 PM
Thats pretty cool. Although I have no clue what-so-ever about php, I would like to learn it. Any quick tutorials you could shoot me to? (And yes...I will be searching by myself, I am not that lazy.) Also, could this same effect be achieved through something a little more simple, like JavaScript? Thanks raf.

-Ben
you're welcome. check out http://www.hotscripts.com/PHP/Tips_and_Tutorials/index.html to get started on PHP.

Something a little more simple? Sorry. I'm all for "universal", "controlable", "thin client" etc. But maybe you're looking at it the wrong way: if you can spend a week or so to get going with PHP, then everything will become a lott simple. After all, it takes me about 10 characters to add this random-image feature ...

Ben@WEBProp
07-20-2004, 05:20 PM
But maybe you're looking at it the wrong way: if you can spend a week or so to get going with PHP, then everything will become a lott simple. After all, it takes me about 10 characters to add this random-image feature ...

Hahaha, you are right! While it would be nice to just get a JS plug into my site, php does sound way better. Perhaps this will give me some motivation to actually learn it and implement it. I will probably start venturing into the php forums to get some serious help. I have e-mailed my host and requested a list of supported languages on their server. They havent gotten back to me yet, but I plan on using php if I can.

Thanks again for your help raf.

-Ben