Simple Banner Rotation & Image Randomizer
Random Image is a straightforward CGI script that randomly selects and displays images from a list you configure. Just point an IMG tag to the script and it serves a random image each time. No Server Side Includes required - perfect for rotating banners, ads, and artwork galleries on any hosting.
Random Image works by serving image data directly to the browser. When you use it as an IMG source, the script picks one image from your configured list at random, reads the image file, and outputs it with the proper Content-Type header. The browser treats it just like any normal image.
<img src="/cgi-bin/rand_image.pl">| File | Description |
|---|---|
rand_image.pl |
Main Perl script (also called image.pl) |
README |
Installation and configuration instructions |
Genuinely random selection from your image list with each page load.
Works with standard IMG tags - no Server Side Includes configuration required.
Supports GIF, JPEG, PNG, and WebP with automatic content type detection.
Just edit an array in the script with your image paths.
Works great in HTML emails - each recipient sees a random image.
Minimal code - just reads a file and outputs it. Simple and reliable.
<img src="/cgi-bin/rand_image.pl" alt="Random Banner">
<img src="/cgi-bin/rand_image.pl" width="468" height="60" alt="Advertisement">
<body background="/cgi-bin/rand_image.pl">
<img src="/cgi-bin/rand_image.pl?t=<?php echo time(); ?>" alt="Random Image">
<div style="background-image: url('/cgi-bin/rand_image.pl');
background-size: cover;
background-position: center;
width: 100%;
height: 400px;">
</div>
rand_image.pl to your cgi-bin directory.
#!/usr/bin/perl
@images array in the script with full paths to your images.
chmod 755 rand_image.pl
http://yoursite.com/cgi-bin/rand_image.pl
<img src="/cgi-bin/rand_image.pl">
Main script (also available as image.pl)
Installation and configuration guide
?t=1766003589 to force new requests.
?set=banners) and use different arrays of images based on the parameter. Or create multiple copies of the script with different configurations and different names.