#!/usr/bin/perl use strict; my $startpath = shift; die "syntax: $0 [directory]\n" if !$startpath; recurse($startpath); sub recurse { my $startpath = shift; opendir DIR, $startpath or die "failed: $startpath $!"; my @bucket = grep !/^\./, readdir DIR; closedir DIR; my @directories = (); my @files = (); my @toolarge = (); foreach my $item (@bucket) { if(-d "$startpath/$item") { push(@directories, $item); } elsif($item =~ /(jpg|bmp|gif|jpeg|png)$/i && $item !~ /^sm_/ && $item !~ /^low_/i ) { my $clipname = $item; $clipname =~ s/^(.+)\.(.+)$/sm_$1\.jpg/; if(!(-e "$startpath/$clipname")) { $item =~ s/\&/\\&/g; push(@files, $item); } else { print "... skipping $item, thumbnail already exists.\n"; } my $lowfile = $item; $lowfile = "low_$item"; my $size = -s "$startpath/$item"; if($size > 80000) { if(!-e "$startpath/$lowfile") { push(@toolarge, $item); } } } } print "cd $startpath\n"; chdir($startpath); foreach (@files) { my $f = $_; $f =~ s/\s/\\ /g; my $out = $f; $out =~ s/\....$/\.jpg/g; print "convert -size 106x80 $f JPG:sm_$out\n"; system("convert -size 106x80 $f JPG:sm_$out\n"); } foreach (@toolarge) { my $f = $_; $f =~ s/\s/\\ /g; print "convert -scale 50% $f low_$f\n"; system("convert -scale 50% $f low_$f"); } foreach (@directories) { recurse($_); } print "cd ..\n"; chdir(".."); }