Random Image

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.

Free Download
Version 1.0
Perl CGI

Overview

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.

How It Works
  1. Browser requests: <img src="/cgi-bin/rand_image.pl">
  2. Script randomly selects an image from the configured list
  3. Script reads the image file from disk
  4. Script outputs the image data with proper headers
  5. Browser displays the image normally
Package Contents
File Description
rand_image.pl Main Perl script (also called image.pl)
README Installation and configuration instructions
Perfect For
  • Rotating banner ads
  • Random photo galleries
  • Sponsor logo rotation
  • Random backgrounds
  • Quote images
  • Seasonal graphics
  • Email newsletters

Features

True Randomization

Genuinely random selection from your image list with each page load.

No SSI Needed

Works with standard IMG tags - no Server Side Includes configuration required.

Multiple Formats

Supports GIF, JPEG, PNG, and WebP with automatic content type detection.

Simple Configuration

Just edit an array in the script with your image paths.

Email Compatible

Works great in HTML emails - each recipient sees a random image.

Lightweight

Minimal code - just reads a file and outputs it. Simple and reliable.

Usage Examples

Basic Usage
<img src="/cgi-bin/rand_image.pl" alt="Random Banner">
With Width/Height
<img src="/cgi-bin/rand_image.pl" width="468" height="60" alt="Advertisement">
As Background (Old Style)
<body background="/cgi-bin/rand_image.pl">
With Cache Busting
<img src="/cgi-bin/rand_image.pl?t=<?php echo time(); ?>" alt="Random Image">
Modern CSS Background
<div style="background-image: url('/cgi-bin/rand_image.pl');
            background-size: cover;
            background-position: center;
            width: 100%;
            height: 400px;">
</div>

Installation

  1. Upload Images
    Upload the images you want to rotate to your web server.
  2. Upload Script
    Upload rand_image.pl to your cgi-bin directory.
  3. Edit Perl Path
    Edit the first line to point to your Perl: #!/usr/bin/perl
  4. Configure Image List
    Edit the @images array in the script with full paths to your images.
  5. Set Permissions
    Make the script executable: chmod 755 rand_image.pl
  6. Test the Script
    Access it directly in your browser: http://yoursite.com/cgi-bin/rand_image.pl
  7. Use in HTML
    Add IMG tags pointing to the script: <img src="/cgi-bin/rand_image.pl">

Download

Compressed Archives
  • image.tar.gz 2.4 KB
  • image.zip 2.6 KB
  • image.tar.Z 3.4 KB
Individual Files
  • rand_image.pl

    Main script (also available as image.pl)

  • README

    Installation and configuration guide

Frequently Asked Questions

They're the same script with different names. Some archives called it "Random Image" (rand_image.pl) and others called it "Image" (image.pl). Use whichever name you prefer - the functionality is identical.

Browsers cache images by URL. Since the script URL doesn't change, the browser may cache the first image. Solution: Add cache-control headers to the script output, or append a random/changing query string like ?t=1766003589 to force new requests.

The basic version outputs raw image data, so you can add alt text in your HTML but not image-specific links. For clickable banners with different URLs per image, use the SSI Random Image Displayer which supports per-image configuration.

Modify the script to accept a query parameter (like ?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.

Yes! JavaScript is now the preferred method. It requires no server resources per image display, supports smooth transitions, and works on any hosting. See the Random Image Displayer page for JavaScript examples. However, CGI versions still work well for email newsletters where JavaScript doesn't run.