Discuss: A Better Image Rotator
by Dan Benjamin
- Editorial Comments
12 sorry, I wasn't very clear
Narrator:
what I meant is, if I’ve got 4 images listed in my ini file, I’d like to have all 4 displayed on my page at the same time – but have the script randomize the order each time the page loads.
does that make more sense?
posted at 11:25 am on August 10, 2004 by nick
13 Kubrick
Only kinda? He looks major psycho! I guess that’s what happens when you’re the greatest director of our time.
posted at 11:32 am on August 10, 2004 by justin
14 Much nicer indeed
I agree that changing the .ini file to an xml file would be ideal, especially if it uses some more semantic markup so as not to scare-off anyone who inherits the updating job. Also, a slick programmer could manage the rotation in a database with an added ‘image_group’ field, removing the need for multiple config files and allowing the creating of a front-end application that could manage the files. Altogether I like like the improvements.
posted at 12:35 pm on August 10, 2004 by Ryan Cannon
15 Thanks.
Excellent.
A great script and huge improvement.
Thanks.
posted at 12:41 pm on August 10, 2004 by gulliver
16 Couple of minor improvements
Very good article, thank you for sharing. I have an image rotator on my site that uses almost exactly the same idea you have here with just a few differences.
For one, I don’t use an .ini file. The ini file parser doesn’t like two double-quotation marks in the middle of a value (e.g. James “007” bond) or ampersands (php 4.3.8). This prevents you from linking to CGI generated web pages, for instance.
Instead I use this for my configuration file:
$src = array();
$href = array();
$alt = array();
$src[] = ‘/img/image-one’;
$href[] = ‘url-one’;
$alt[] = ‘alt-for-image-one’;
$src[] = ‘/img/image-two’;
$href[] = ‘url-two?cgi=value&another=cgi-value’;
$alt[] = ‘alt-for-image-two’;
Second, I wrap all usage of those values in the script in an htmlentities() call. That escapes characters that might break the anchor or img tags generated by the script.
Like this:
echo ‘alt=”’.htmlentities($alt[$index]).’”’;
posted at 04:25 pm on August 10, 2004 by john
17 Even more flexible
Why only images? Why .ini-files?
We could as well just include a random (x)html-fragment from a directory (similar to the first roationscript), and with a single script we get image-rotation, or flash-rotation or article-rotation or …..
The advantage of a configuration file (may it be .ini, xml or database driven) is, that we get some sort of simple documentation in one file for free. But it wouldn’t be complicated to put the html-fragments into one config-file.
posted at 05:55 pm on August 10, 2004 by Imre
19 COOL, I'm Using it Right now
I did a little tweak on the php file as well as the include part… I added $_SERVER[“DOCUMENT_ROOT”].”/path/to/rotate.php” same thing with the ini src one the rotate.php itself… but all in all, it really works great and loads fast.
posted at 09:07 pm on August 10, 2004 by Joachim Guanzon
20 getimagesize is buggy
Just an FYI to any of your readers who try this and are having troubles with it: http://bugs.php.net/bug.php?id=28029 is what I learned of when I tried a hack on my blog app that used getimagesize() to (duh) get the image’s size. According to the posts in the blog app’s forum there are different types of buggyness available. I got a long delay before no values were returned, others had a fixed set of values returned, and some had problems with only certain image types or images of rather large byte or pixel sizes.
posted at 09:29 pm on August 10, 2004 by EdB
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.
Subscribe to this article's comments: RSS (what’s this?)






11 JavaScript?
I did mine in Flash. :)
And Stanley Kubrick looks like kind of a psycho …
posted at 11:11 am on August 10, 2004 by Rob Cameron