A LIST Apart: For People Who Make Websites

No. 160

Discuss: Random Image Rotation

Pages

 <  1 2 3 4 >  Last »

11 *sigh*

For that matter, can you tell that I didn’t notice the “HTML displays as Source; it does not render.” message?

Either that, or I just assumed that everyone hear is a native speaker of HTML. Yeah, that’s it…

posted at 07:51 am on October 22, 2003 by Stephen Sample

12 Brill!!!

You just made my life so much easier!!!

Thanks

posted at 07:52 am on October 22, 2003 by Ian

13 Perl CGI variation

We’ve been running a CGI script to do the same thing, inserted as an include into the webpage – drop us a line for more :)

posted at 08:18 am on October 22, 2003 by Rob Sayles

14 Redirect instead of passing through

I also wrote a php script like this (don’t have the sourcecode near me athm though) but instead of giving the contents of the image, it redirects the browser to the url of the image using the Header(“Location: “) command.

This way you can save bandwith since the image can be cached instead of being downloaded over and over again.
Just my $0.02 :)

posted at 08:18 am on October 22, 2003 by Simon Drijver

15 Huge security bug!

There are a couple bugs in this script that together make for a huge security issue.

I’ve emailed the author with details.

Please don’t use this script until the author can post the updated version. It is a simple fix, so I’m hoping we’ll see the update soon.

posted at 10:37 am on October 22, 2003 by Justin Greer

16 The image folder

One problem with the script is the way in which the list of files is generated. You can have some problems with operating systems which generate preview icons for the files. For example on OS X you get hidden files that contain the preview which are very similar in name to the actual image. The important point is that they also have the same extention. The filenames start as with a ‘.’ and so do not show up in the Finder but are included in the list of images to circle through. If the script decides to use one of these images then you will get no content displayed. The only way to solve this problem (in OS X) is to use the Terminal to delete the icon previews and then not to open the pictures in an application that will generate them again.

Or you can modify the regular expressions used in the scripts to exclude files that start with a ‘.’.

posted at 10:53 am on October 22, 2003 by Lllama

17 Easily adaptable for multiple images

A small modification — fill an array, then randomly sort — allows multiple images to be selected without danger of showing the same image in two spots at once: see http://www.terriertribe.com/ for an example.

posted at 11:10 am on October 22, 2003 by Steven Spicer

18 Validation, Layout and Accessibility

The script works exactly as promised and is useful, but I don’t like that the height, width, and alt attributes are ignored. This causes problems both for accessibility and for validation. Obviously you could stick an alt=”“ to help validate, but that defeats the alt purpose.

Also without dimensions, you can’t reliably float the image.

Since the server is running PHP you could, in theory, use <% include “rotate.php?alt=alt_text”; %> where rotate.php would generate the entire <img> tag, including height, width and alt.

posted at 11:26 am on October 22, 2003 by August Trometer

19 ASP's easy...

There are a number of different ways of doing this via ASP

Basically it involves consitantly naming your images, ie; image1.jpg, image2.jpg, etc…

then randomize a number and pass it to your image tag…

image<i>.jpg

(obviously width, height, alt should be included)…

But it’s as simple as that.

I’ve modified it to drop a cookie on the client for the time their browser’s open, so if they return to the site during the same session, it’ll draw the same image…if the bowser’s closed…then the cookie deletes and they get a new image next time they visit…

Obviously there’s probably a few other ways of doing this but this one works…

works for me…

posted at 11:34 am on October 22, 2003 by Jon-Paul LeClair

20 Interesting

I’ll be interested to see the debugged version of this. I’ve been using a javascript include to do this for several years. It’s fairly simple and when I add new images, I just name them accordingly and edit the maxnumber to equal the highest image number. Seems to work fairly well.

[removed]
<!—

var maxnumber=122;
var randomnumber=Math.floor(Math.random()*maxnumber)+1;

//—>
[removed]

posted at 11:43 am on October 22, 2003 by Steph Mineart

Pages

 <  1 2 3 4 >  Last »

Discussion Closed

New comments are not being accepted, but you are welcome to explore what people said before we closed the door.

Got something to say?

Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.

Create a new account or sign in below if you’d like to leave a comment.

Remember me

Forgot your password?

Subscribe to this article's comments: RSS (what’s this?)