Imagemagick Thumbnail Script.

Updated here

This is a perl script that I whipped up to rapidly turn lots of images into thumbnails. It will drive imagemagick (default install in redhat, availiable for nt/win and other platforms) to produce thumbnails, medium sized images, and full resolution.

For this to work with NT, you will need to change path characters to “\\”. You also need to set the path to your imagemagick installation.

Command line examples:

thumb.pl /var/dropbox/photos /home/erics/photos
thumb.pl /var/dropbox/photos /home/erics/photos-r "-rotate 90"

That’s thumb.pl – source dir – dest dir – options

Watch line wrapping, some of the lines are really long.

# Copyright (c) Eric Soroos 2000
# Permission to use, copy, modify, distribute, and sell this software 
# for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation.  No representations are made about the suitability of this
# software for any purpose.  It is provided "as is" without express or 
# implied warranty.

$targetExtension = "(jpg)|(tif)|(bmp)";
$thumbnailExtension = "jpg";
$thumbnailSize = "133x133";
$mediumSize = "400x400";
$thumbnailName = "-tm";
$mediumName = "-md";
$lgName = "-lg";
$pathToIm = "/usr/X11R6/bin/";

($startDir, $destDir, $options) = @ARGV;

opendir (START, $startDir) || die "Couldn't Open Start dir: $startDir";

@files = readdir(START);

closedir (START);

if (not -d $destDir) {
	mkdir ($destDir, 0775);
open (OUTFILE, ">$destDir/index.html") or die "Couldn't open index.html";
open (OUTFILE2, ">$destDir/index2.html") or die "Couldn't open index2.html";

foreach $file (@files) {
	($fname,$extension) = split(/\./,$file);
	if ($extension =~ /$targetExtension/i) {
		`$pathToIm/convert $options -interlace NONE \"$startDir/$file\" \"$destDir/$fname$lgName.$thumbnailExtension\"`;
		`$pathToIm/convert $options -interlace NONE -geometry $mediumSize \"$startDir/$file\" \"$destDir/$fname$mediumName.$thumbnailExtension\"`;
		`$pathToIm/convert -interlace NONE -geometry $thumbnailSize \"$destDir/$fname$mediumName.$thumbnailExtension\" \"$destDir/$fname$thumbnailName.$thumbnailExtension\"`;

	print OUTFILE "\n";
	print OUTFILE2 "\n";

close OUTFILE;
close OUTFILE2;

No comments

No comments yet. Be the first.

Leave a reply

You must be logged in to post a comment.