Gossamer Forum
Home : General : Perl Programming :

Image Rotation

Quote Reply
Image Rotation
Hi,
Is it possible to have images rotate (refresh) from within my html templates using some perl code?
I want my images to change every 5 seconds without the user having to refresh their browser.
Is this possible using perl in a global subroutine?

PS. The html templates are generated by GT scripts (e.g DBMan SQL, etc.)

Thanks.
Quote Reply
Re: [jai] Image Rotation In reply to
Hi,

Do you mean something like the image on the top-right of this page? http://ambeautiful.co.uk/

You're best bet is to have a look at the HTML, and see how its done (don't have time to pick it out for you I'm afraid :/).

Hope that helps Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [jai] Image Rotation In reply to
Hi,

It's not something perl can do. You'd have to do it with javascript or dhtml.
Quote Reply
Re: [Andy] Image Rotation In reply to
Thanks Andy!
The site you provided uses java (copy below if anyone needs it) but I didn't want to use java if possible.
Any other ideas? Gmail suggested dhtml (thanks) but I don't know how to code it.
Simon.


<script type="text/javascript">

function initImgRotation() {
// create rotating image objects here
// arguments: image name, rotation speed
var rotator1 = new rotateImgObj('img1',5000);
// add the images to rotate into that image object
rotator1.addImages("shop_front.gif", "small-752.gif", "small-748.gif", "small-746.gif", "small-725.gif", "small-737.gif", "small-732.gif");
rotator1.rotate();


rotateImgObj.start();
}

// If all the images you wish to display are in the same location, you can specify the path here
rotateImgObj.imagesPath = "/gallery/";

// no need to edit code below
/////////////////////////////////////////////////////////////////////
rotateImgObjs = []; // holds all rotating image objects defined
// constructor
function rotateImgObj(nm,s) {
this.speed=s; this.ctr=0; this.timer=0;
this.imgObj = document.images[nm]; // get reference to the image object
this.index = rotateImgObjs.length; rotateImgObjs[this.index] = this;

this.animString = "rotateImgObjs[" + this.index + "]";
}

rotateImgObj.prototype = {
addImages: function() { // preloads images
this.imgObj.imgs = [];
for (var i=0; arguments; i++) {
this.imgObj.imgs = new Image();
this.imgObj.imgs.src = rotateImgObj.imagesPath + arguments;
}
},

rotate: function() {
if (this.ctr < this.imgObj.imgs.length-1) this.ctr++;
else this.ctr = 0;
this.imgObj.src = this.imgObj.imgs[this.ctr].src;

}
}

// sets up rotation for all defined rotateImgObjs
rotateImgObj.start = function() {
for (var i=0; i<rotateImgObjs.length; i++)
rotateImgObjs.timer = setInterval(rotateImgObjs.animString + ".rotate()", rotateImgObjs.speed);
}
</script>




<body bgcolor="#f1e0f0" leftmargin="0" topmargin="0" bottommargin="0" marginheight="0" marginwidth="0" onload="initImgRotation()">

<img name="img1" src="gallery/shop_front.gif" width="150" height="113" alt="" style="border: 1px solid #000000"><br>

Quote Reply
Re: [jai] Image Rotation In reply to
Is there a particular reason why you don't want to do it using javascript?

As a side note, you mentioned that the site Andy recommended uses java - it is actually javascript. Java and javascript are different languages.

Last edited by:

Gmail: Feb 4, 2005, 3:31 PM
Quote Reply
Re: [Gmail] Image Rotation In reply to
I wanted something that would work if some users don't/can't use javascript.
Thanks
Quote Reply
Re: [jai] Image Rotation In reply to
Would I run into problems (from a users' browser point of view) if I used -
<META http-equiv="Refresh" content="30">
and had a random image display on each refresh?

Is there really no perl option??????

Thanks.



I just found this -
http://search.cpan.org/~jhi/perl-5.8.0/lib/CGI/Push.pm
I haven't read/tried it yet but it looks like it may do what I want.
Has anyone tried it?

Last edited by:

jai: Feb 5, 2005, 4:23 PM
Quote Reply
Re: [jai] Image Rotation In reply to
Perl is a server-side scripting language. You can use perl to generate javascript or dhtml in order to do the rotation but you can't do it with pure perl code alone.

Quote:
Would I run into problems (from a users' browser point of view) if I used -
<META http-equiv="Refresh" content="30">
and had a random image display on each refresh?

Probably not, but it's not the most elegant solution. If you go to somewhere like dynamicdrive.com you'll find some nice dhtml examples.

Last edited by:

Gmail: Feb 5, 2005, 5:18 PM
Quote Reply
Re: [jai] Image Rotation In reply to
I missed the part about CGI::Push.

I would leave that alone - server push isn't supported by Internet Explorer.
Quote Reply
Re: [Gmail] Image Rotation In reply to
Thanks Gmail.
There is some good scripts at dynamicdrive.com and I will use the <noscript></noscript> tags to include alternative content for users without javascript (or with it swiched off).
As you said, I can use the perl to serve up the javascript and I have incorporated it within a global subroutine within my html template.
Thanks for your help.
Simon.