Thank you very much for this script. I dropped in straight onto my box and
ran it beautifully.
However, I've got a couple of questions about the code.
On Wednesday 27 March 2002 6:46 pm, Randal L. Schwartz wrote:
> #!/usr/bin/perl
> use strict;
>
> use Image::Magick;
>
> my $im = Image::Magick->new;
>
> umask 0022;
>
> my @names = @ARGV ? @ARGV : grep { -f and -B } <*>;
I read this to say, if filenames passed use them otherwise do the whole of
the current directory. I believe that the grep takes the list provided by
<*> performs the -f and -B filters on the list and assigns the result to
@names. Am I correct, and what does the -f and -B do?
>
> for (@names) {
> if (/ /) {
> my $old = $_;
> tr, ,_,s;
> $_ .= ".jpg" unless /\.jpg$/;
> ! -e and rename $old, $_ or next;
> warn "renaming $old to $_\n";
> }
I see the above renames any file containing spaces to include '_' instead
> next if /\.thumb\.jpg$/;
> my $thumb = "$_.thumb.jpg";
> next if -e $thumb;
skip to next if this is a thumbnail, or if the thumbnail already exists
> undef @$im;
This one confused me. I'm assuming that it's resetting the variables used by
the object $im, while keeping the object intact. If this is correct, is this
something specific to Image::Magick, or can a similar method work with most
objects?
> my $ret;
> $ret = $im->Read($_)
> and warn($ret), next;
> $ret = $im->Scale(geometry => '100x100')
> and warn($ret), next;
> $ret = $im->Write($thumb)
> and warn($ret), next;
I can see what you're getting at here, but I want to make sure I understand
the mechanic.
If $im->Read fails, it assigns an error value to $ret, which in turn returns
true. Only if the assignment is true, will the second half of the 'and'
execute giving the warning and skipping
> warn "thumbnail made for $_\n";
> }
>
> This creates a thumb that is proportional, but at most 100pxl in
> either dimension. ImageMagick does all the math. :)
Once again, thanks for the help
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]