N E T B U I E dot net
Occasionally making sense since 1966

April 28, 2003

New photos

I've uploaded new scans of pretty much every photo on the site, plus some new ones. The new photos are being loaded into the random image script on every page, but it'll take some time to replace all the hard-coded images on each of the photo pages.

It took a long time to scan all the negatives and slides, and then go through some attempt at color correction and removing dust and scratches, so I wasn't too thrilled with the idea of resizing each one individually, or even going through recording a Photoshop action to do it. So, the logical thing was to use Imagemagick and perl.

Imagemagick is a free command-line image processing utility that runs on unix and linux boxes. And Mac OS X! The advantage of using it over Photoshop is that since it is command-line, it can be incorporated into scripts. It's nowhere near as functional as Photoshop, but for resizing a large number of TIFFS, it's ideal.

The Imagemagick command is embedded in a perl script that reads the contents of a directory (TIFF files sorted by horizontal or vertical aspect) and plugs each one into the command. The script gets the name of each file (eg, 94fb10.tif) and saves the output as a correctly-named jpeg (eg, 94fb10.jpg).

I have four separate scripts, two each (one for large, one for thumbnails) for horizontal and vertical. If I was a half-decent perl scripter, I'd just have one script that would detect the aspect and resize accordingly. But...

Anyway, here's the script:

#!/usr/bin/perl
#
# resize.pl sourcedir destdir "options"
#

$targetExtension = "(jpg)|(tif)|(bmp)";
$thumbnailExtension = "jpg";
$thumbnailSize = "194x";
$mediumSize = "780x";
$thumbnailName = "-sm";
$mediumName = "-lg";
$pathToIm = "/usr/local/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);
}

foreach $file (@files) {
($fname,$extension) = split(/\./,$file);
if ($extension =~ /$targetExtension/i) {
`$pathToIm/convert $options -interlace NONE -filter Lanczos -geometry $mediumSize -unsharp 1x2+1.2+.08 -border 10x10 -bordercolor black -quality 75 "$startDir/$file" "$destDir/$fname$mediumName.$thumbnailExtension"`;

}
}

The script takes three arguments, source directory, target directory, and imagemagick options that aren't already specified. I cropped all the images to a 3:2 (or 2:3) aspect ratio, so they should all be the same dimension after resizing. The -filter option specifies which resampling method to use when down-sampling during the resize. The -unsharp option is an unsharp mask filter with radius x std dev + amount + threshold. The -quality option specifies the jpeg compression level.

It took about an hour to generate a pair of images (large and thumbnail) for all the source images. Much faster than doing it either manually or via actions in Photoshop.

Posted by jbuie at April 28, 2003 09:32 PM
Comments
Post a comment









Remember personal info?