Gossamer Forum
Home : General : Perl Programming :

Random Image

Quote Reply
Random Image
Hi Folks

Wandering if you could help me? I want to create a HTML file but I want a different image to appear on one section. I just want a tiny snippet of HTML to display a differnet image. The two pieces of codes I will need is this:

<IMG SRC="skip.gif" BORDER="0">
<IMG SRC="skate.gif" BORDER="0">

So that the file will print either one of those codes depending on some kind of randomness. Nothing complex. Just make a random number between 1 and 2 I guess? Anyway, any snippet of code would be helpful.

Rgds
Wiliam Stephens



Quote Reply
Re: Random Image In reply to
If all you want is to have a small number of images appear in a random fashion...use javascript like the following:

Code:

<script language="javascript">

var dt = new Date();
var sec = dt.getSeconds();

if (sec<=10)
{
document.write
('<P><IMG SRC="pic1.jpg" WIDTH=360 HEIGHT=240>');
}

else if (sec<=20)
{
document.write
('<P><IMG SRC="skate.gif" BORDER="0">');
}


else if (sec<=30)
{
document.write
('<P><IMG SRC="skip.gif" BORDER="0">');
}


else if (sec<=40)
{
document.write
('<P><IMG SRC="skate.gif" BORDER="0">');
}


else if (sec<=50)
{
document.write
('<P><IMG SRC="skip.gif" BORDER="0">');
}

else
{
document.write
('<P><IMG SRC="skip.gif" BORDER="0">');
}
</script>


Now...if you want a more robust "banner" program, try searching the following web sites:

http://www.perlarchive.com
http://www.hotscripts.com
http://cgi.resourceindex.com

Regards,

Eliot Lee
Quote Reply
Re: Random Image In reply to
Thank you for your tid-bit of code. That works well and it speeds the page up a lot than using Perl/CGI.

Rgds
Wiliam Stephens

Quote Reply
Re: Random Image In reply to
Actually if you want to go the javascript route, try this:

PUT THIS IN <head> PORTION OF PAGE

<script language="javascript">
function Rand (a){
var b = (a-1)*Math.random()+1;
var c = Math.round(b);
return c;
}

var round = Rand(10);

images = new Array
images[1] = "http://yourimage.gif"
images[2] = "http://yourimage.gif"
images[3] = "http://yourimage.gif"
images[4] = "http://yourimage.gif"
images[5] = "http://yourimage.gif"
images[6] = "http://yourimage.gif"
images[7] = "http://yourimage.gif"
images[8] = "http://yourimage.gif"
images[9] = "http://yourimage.gif"
images[10] = "http://yourimage.gif"
var image = images[round]
</script>


AND PUT THIS IN THE BODY

<script language="javascript">
document.write('<IMG SRC="' + image + '" border="0">')
</script>


If you want to add or subtract images just change var round = Rand(10); to the number of
images you want to display. And change the array to reflect it also.

Later,
Paul

http://www.fullmoonshining.com for Pearl Jam Fans
Quote Reply
Re: Random Image In reply to
Thank you for your reply. I think I will use the first suggestion, though, as it allows me to define differnet WIDTH and HEIGHT attributes for all images therefore increasing download speed on that page.

Rgds
Wiliam Stephens

Quote Reply
Re: Random Image In reply to
In Reply To:
increasing download speed on that page.
Don't you mean decreasing[/red] download speed?

Increasing = More Time
Descreasing = Less Time

Regards,

Eliot Lee
Quote Reply
Re: Random Image In reply to
Eliot,

You must need some coffee. Increasing the speed of something means making it faster. We're talking about increasing download speed, not download time.

Quote Reply
Re: Random Image In reply to
Uh...let's see now....I totally disagree with you...

Increase = make more, add to, fill in
Decrease = make less, add from, take away

IN MY BOOK...INCREASING download speeds MEANS INCREASING THE TIME IT TAKES TO DOWNLOAD A WEB PAGE, GOT IT????

Mad

Regards,

Eliot Lee
Quote Reply
Re: Random Image In reply to
Uh, Im afraid you have it backwards. How would you like your ISP to INCREASE the time it takes you to download a file? How about INCREASING your drive time to work? You said it yourself:

Increase = make more, add to, fill in
Decrease = make less, add from, take away

Therefore, if a page takes 3 seconds to load and we DECREASE the speed at which it loads then the load time of the page will be greater than 3 seconds! GOT IT???

Can anyone back me up on this?


Quote Reply
Re: Random Image In reply to
Speed is a relative concept...therefore, the absolute measurements applied reflect their true meaning....in other words, you say "potatoe", I say "potato". Wink

Regards,

Eliot Lee
Quote Reply
Re: Random Image In reply to
Indeed I was talking about increasing the download speed. That is; making the speed of the download faster. Maybe I used the wrong grammer but in the context of my message the phrase should have been read as making my page download at a greater speed.

Rgds
Wil Stephens

Quote Reply
Re: Random Image In reply to
ANTHRO...you are wrong!

INCREASING download speed DECREASES the time it takes for a page to load!

In Reply To:
IN MY BOOK...INCREASING download speeds MEANS INCREASING THE TIME IT TAKES TO DOWNLOAD A WEB PAGE, GOT IT????
Anthro..you have NO right to be SO rude to people. Again I have to comment on your behaviour because AGAIN you have used unnecessary rudeness!

Its just ironic that you are wrong about the point you are trying to make!

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Random Image In reply to
ok... after looking over this thread for some time and thinking eliot went out of his mind.. i finally understood...

eliot is right.. just the way it was said made it confusing....

decreasing download speeds

everyone was thinking eliot meant the rate the connection goes.. but eliot meant...
SPEED = TIME IT TAKES TO DOWNLOAD A WEB PAGE

so its equally right to say decreasing download times..

both ways are actually correct depending on your meaning of the word speed... it could be swiftness.. and in terms of downloads it could be how quickly the download was complete (or time)..

in my opinion... wil meant swiftness.. anthro understood the three words opposing your understandings and stated the fact he thinks it was decreasing.. BennyHill, wil, and then PaulWilson replied without giving this situation enough thought..

see.. i also went along with you guys.. i thought anthro was crazy.. but i wouldn't think after 2 people clearing it up for him he'd still go along with his idea of the situation.. so i tried to put myself in his perspective and realized he was also right..

PaulWilson.. Anthro was just making his point that he believes increasing speed = increasing time.. after reading this over and over i figured it out.. speed = time.. how is this so rude to people.. he has every damn right to be so rude to anyone.. he lives in america :) i don't know about you people in Great Britain.. but i'm sure anyone anywhere will protect what he believes in..

don't tell someone they are wrong when they are right..

I do blame you.. :P

Jerry Su
widgetz sucks
Quote Reply
Re: Random Image In reply to
lol

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)