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__
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|