Depending on how you process your images, it may be wise to try and reuse a single IM object. This code shows a possible IM glitch which you may run into. It shows the need to clear out the reusable IM object after every use. However, you may get away with a creation/undef usage within a limited scope, where you create a new IM object for every transformation, then undef it. I think that would slow you down with alot of images, so think about a reusable IM object.
#!/usr/bin/perl
use warnings;
use strict;
use Image::Magick;
my $image = Image::Magick->new;
umask 0022;
my @pics= <*.jpg>;
#my @pics= <*.jpg *.gif *.png>; #add all your extensions here
foreach my $pic (@pics){
my ($picbasename) = $pic =~ /^(.*).jpg$/;
my $ok;
$ok = $image->Read($pic) and warn ($ok);
my $thumb = $picbasename . '-t.jpg';
$image->Scale(geometry => '100x100');
$ok = $image->Write($thumb) and warn ($ok);
undef @$image; #needed if $image is created outside loop
print "$pic -> $thumb\n";
}
And here is a very basic File::Find script to process files.
#!/usr/bin/perl
use File::Find;
$|++;
my $path = '.';
my $cmd = 'file';
finddepth (\&wanted,$path);
# untested regex
my $regex = qr/\Q.png$\E/i;
sub wanted {
return unless -f; #-d for dir ops or comment out for both
if ( /$regex/) {
print "$File::Find::name\n"
#do your ImageMagick processing here
}
}
__END__