The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -w
use strict;
use Tk;
BEGIN {
    if (!eval { require Tk::JPEG::Lite }) {
	eval { require Tk::JPEG };
	die $@ if $@;
    }
}
use Getopt::Std;
eval { require Tk::PNG; };

my $mw  = MainWindow->new();
print "vis=",$mw->visual," d=",$mw->depth,"\n";
my ($vis) = grep(!/\b8\b/,grep(/truecolor/,$mw->visualsavailable));
my @args = ();
if ($vis)
 {
  print $vis,"\n";
  $mw->destroy;
  $mw = MainWindow->new(-visual => $vis);
 }
else
 {
  @args = (-palette => '4/4/4');
 }
# print "vis=",$mw->visual," d=",$mw->depth,' "',join('" "',$mw->visualsavailable),"\"\n";
my %opt;
getopts('f:',\%opt);
if ($opt{'f'})
 {
  push(@args,'-format' => $opt{'f'});
 }
unless (@ARGV)
 {
  warn "usage $0 [-f format] <imagefile>\n";
  exit 1;
 }
my $file = shift;
my $image = $mw->Photo(-file => $file, @args);
#print join(' ',$image->formats),"\n";
print "w=",$image->width," h=",$image->height,"\n";
$mw->Label(-image => $image)->pack(-expand => 1, -fill => 'both');
$mw->Button(-text => 'Quit', -command => [destroy => $mw])->pack;
MainLoop;

__END__

=head1 NAME

tkjpeg - simple JPEG viewer using perl/Tk

=head1 SYNOPSIS

  tkjpeg imagefile.jpg

=head1 DESCRIPTION

Very simplistic image viewer that loads JPEG image, and puts it into a
Label for display.

=head1 AUTHOR

Nick Ing-Simmons <nick@ni-s.u-net.com>

=cut