#!/usr/local/bin/perl
use strict;
use warnings;
use File::Copy qw(mv);
my $imagepath = '/var/www/images';
opendir DIR, $imagepath or die "could not open $imagepath: $!";
while (my $file = readdir DIR) {
next unless ($file =~ /\.JPG$/);
my $nfile = $file;
$nfile =~ s{\.JPG$}{.jpg};
mv $file, $nfile or die "could not rename $file to $nfile: $!";
system("convert \"$nfile\" -resize 120x120 120x120 \"$nfile\"") == 0 or warn "convert $nfile failed: $?";
}
closedir DIR;
|