#!/usr/local/bin/perl
#
# Display one or more images as a montage to an X server.
#
# Author: John Cristy (cristy@dupont.com)
#
@filenames=@ARGV;
if ($#filenames < 1)
  {
    #
    # Read filenames within a directory.
    #
    $image_directory='/usr/home/images' unless $image_directory=shift;
    opendir(directory,$image_directory) || 
      die "Images directory is not available: $!\n";
    @filenames=sort(grep(!/^\.\.?$/,readdir(directory)));
    closedir(directory);
    chdir($image_directory) || die "image directory is not available: $!\n";
  }
#
# Display 20 images at a time as a montage image.
#
while ($#filenames > 20)
{
  system 'montage', '-verbose', '-geometry', '160x160+5+5', '-tiles_per_row',
    '5', '-frame', '-borderwidth', '5', '-background', '#103040', '-foreground',
    'white', '-mattecolor', 'SlateGray', '-label', '%f   %wx%h',
    @filenames[0..19], "montage.$$";
  system 'display', '-iconic', '-use_pixmap', "montage.$$";
  system '/bin/rm', "montage.$$";
  @filenames=@filenames[20..$#filenames];
}
system 'montage', '-verbose', '-geometry', '160x160+5+5', '-tiles_per_row',
  '5', '-frame', '-borderwidth', '5', '-background', '#103040', '-foreground',
  'white', '-mattecolor', 'SlateGray', '-label', '%f   %wx%h', @filenames,
  "montage.$$";
system 'display', '-iconic', "montage.$$";
exec '/bin/rm', "montage.$$";
exit(255);
