#!/usr/bin/perl -wT use strict; use CGI qw(:standard); use Image::Magick; print header, start_html('Thumbnails'), h1('Thumbnail Images'); unless(opendir(IN,"./")) { print "Couldn't open directory ($!)"; exit; } my @files = grep { !/^tn_/ and /\.jpe?g$/ } readdir(IN); closedir(IN); foreach (@files) { unless (-e "tn_$_" && ((stat("./tn_$_"))[9] > (stat($_))[9])) { my $image = new Image::Magick; print STDERR "Unable to Read() $_" if $image->Read($_); my ($o_width, $o_height) = $image->Get('width', 'height'); my $tn_width = $o_width * .25; my $ratio = $o_width / $o_height; my $tn_height = $tn_width / $ratio; $image->Sample(width => $tn_width, height => $tn_height); $image->Write("tn_$_"); } print qq($_
$_

); } print qq();