#!/usr/bin/perl -w use strict; use Tk; use Tk::JPEG; use Tk::PNG; use Image::Magick; use MIME::Base64; my $val = 0; my $im = Image::Magick->new; # a single object for thumbnails my $c; my $dir = "."; my @fl = <*.jpg *.png *.gif>; print "@fl\n"; my $main = new MainWindow; my $photo_obj = $main->Photo(-file => '' ); my $display = $main->Label(-width => 200, -height => 200, -image => $photo_obj, )->pack(-fill=>'both', -expand=>1); &loadpic( $fl[0] ); my $frame = $main->Frame()->pack(); my $nxt = $frame->Button(-text => "Next", -command => \&nextp)->pack(-side=>'left'); $frame->Button(-text => 'exit', -command => sub{destroy $main} )->pack(-side=> 'left'); $frame->Checkbutton( -onvalue => 1, -offvalue => 0, -text => 'Charcoal', -variable => \$val)->pack(-side=> 'left'); $main->bind("", sub { $nxt->invoke }); MainLoop; sub loadpic { my $filename = shift; $photo_obj->blank; #clear out old jpg my ($h,$w) = ($display->height, $display->width); # # how to scale the pic? # Create new size version $im->Read($filename); $im->Scale( geometry => $w.'x'.$h ); if($val){ $im->Charcoal('0x1') } #Tk needs base64 encoded image files my $data = encode_base64( $im->ImageToBlob() ); undef @$im; # blank $im object $photo_obj->put($data); $display->configure(-image => $photo_obj); } sub nextp { push (@fl,shift(@fl)); #circular list my $f = $fl[0]; loadpic("$dir/$f"); }