Free Perl CGI Scripts

This page contains two free perl scripts, the image Gallery Generator and the sort script.

Free Perl Image Gallery Generator



This script does not generate a whole page for your gallery, just the code you need to paste into your standard domain pages to create a profesional looking gallery (please note; this does not work with WordPress, I wrote this long before I started my blog).

The gallery script (link at the top of page) will re-size your photos to the dimensions you set (it will also correctly manage mixed galleries of portrait and landscape photos), it will then annotate them (with whatever text you set) and place them into a gallery folder of your choosing. Next it will create the thumbnails, at a size of your choice, and place them into a folder of your choice, and finally it will generate html code that you can paste into an existing web page.

The default script html uses CSS floats to make an image gallery that will adjust the number of images per row, and the number of rows, to match the width of your page. This is based on the float tutorial provided here. The generated html also uses the Lighbox.js script, which is described here.

This script requires Perl, Image Magick and the Image Magick perl plugins, just place it (the script) into a folder with the images you want converted (and only the images, the script will fall over if it comes across unknown filetypes, or tries to convert a folder), set up the annotation, folder and image size options, and run the script. Please note by default this script will delete the original image, but that can be commented out (however I’d still recommend not using this script on the only copy of your holiday snaps).

Due to a bug the Lighbox.js script might not run if your webpage has the standard Javascript status-bar modification command:


<body onLoad="window.status='Hello World';return true">

To solve this, and still use status-bar text, try the Javascript script that I use (which is placed in the head of the sample page if you want to see it in action).

I have added the following to my style sheet (I use a linked cascading style sheet, but the following should be able to be added to any embeded CSS) to make the gallery work (note; this refers to my old site, not this site):


/*Image Gallery section*/
	padding: 10px;
	border-bottom: 2px solid #666;
	border-right: 2px solid #666;

	font-size: 0.8em;
	padding-top: 0.4em;

#lightboxCaption{ float: left; }

#keyboardMsg{ float: right; }

#lightbox img{ border: none; } 

#overlay img{ border: none; }

#overlay{ background-image: url(; }

#closeButton{ top: 5px; right: 5px; }

* html #overlay{
	background-color: #333;
	background-image: url(blank.gif);
	filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src="", sizingMethod="scale");

.thumbnail {
	float: left;
	width: 120px;
	height: 120px;
	margin: 15px;
	text-align: center;

.clearboth { clear: both; }

Sort Script


This is a very specialist script but I hope someone can find a use for it. I wrote this script to sort a huge collection (2500+) of photos that were sent to me as a *.zip file which didn’t have any directory structure information.

The images were survey shots which were named by numbered site and then described, so one of the shots for site ABC which was of a tree would be named ABC_photo-of-tree.jpg. I wanted each set of photos sorted into folders by site name, so I wrote this script to read in the file name, create a folder based on whatever came before the underscore (in the above example the folder would be ABC) and then move the photos into it. It took a few minutes to write, and the whole set of photos were then sorted within seconds.

The script can be re-written to use any delimiter.

  • Add Comment Register
    You may use these HTML tags: <a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <strike> <strong>

  • Comment Feed for this Post
Go to Top