Page 1 of 1

simple montage use [noob]

Posted: 2009-01-02T14:38:49-07:00
by jeffATwork
I'm writing a Perl script to produce "contact sheets" of larger TIF images. We want to be able to produce sheets of thumbs for all the TIF files in a specified directory. (I know, this should be simple, but ...)

I thought the process would be something like:

make a new IM object
use opendir/readdir to loop through the directory reading each TIF into the IM object
use Montage to transform the IM object into, well, a montage
write the IM object out as a PNG

But, my code is producing single PNG files for each of the original TIFs and at the size of the original at that.

Here's my code snippet:

my $contact_sheet=Image::Magick->new;

opendir(TIF_DIR, $tif_dir) or die "Can't open $tif_dir: $!";
my $filename;
my $magickReturn=0;
while (defined ($filename=readdir(TIF_DIR))) {
if ( $filename ne '.' and $filename ne '..') {
$magickReturn += $contact_sheet->Read(filename=>$tif_dir . "/" . $filename);
}
}
closedir TIF_DIR;
print "$magickReturn TIFs read.\n"; # this prints out that 50 have been read

$magickReturn = $contact_sheet->Montage(geometry=>'72x89', tile=>'8x12');
print "Montage returned $magickReturn\n"; " the returned value is an array

$magickReturn = $contact_sheet->Write(filename=>$output_file . ".png");
print "Write returned $magickReturn\n";

I don't know what the last print statement would produce. I killed the process when I saw that it was producing a file for each of the original TIFs.

What am I doing wrong?

Any help gratefully accepted!

Re: simple montage use [noob]

Posted: 2009-01-02T15:25:59-07:00
by jeffATwork
Aha!

The Montage method returns the montaged image!

Great!!