#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; use Tk::JPEG; use MIME::Base64; use Imager; use File::Basename; use File::Path; use File::Copy; use Storable; use POSIX qw(strftime); use YAML; my $photo;#my $photo; my $image; my %info; my @exts = qw(.jpg .png .gif); # list allowed extensions if(-e 'notebook.db'){ %info = %{retrieve('notebook.db')}; # direct to hash }else{ make_thumbs() } #to see a dump of the db, just put an 1 as an arg to the script if(shift){print Dump(\%info);exit;} my $mw = MainWindow->new(-bg=>'black'); $mw->geometry('800x700+100+15'); #setup auto save of storable db $mw->protocol('WM_DELETE_WINDOW' => sub { &save_it() }); $SIG{__DIE__} = sub { &save_it()}; $SIG{INT} = sub { &save_it()}; $mw->bind('', [sub{&save_it(); Tk::exit;}] ); my $mainframe = $mw->Frame(-background=>'black') ->pack(-side => "right", -anchor => "n", -fill=>'both', -expand=>1); #fill mainframe with default screen setup_pane(); MainLoop; ################################################ sub setup_pane{ my $pane = $mainframe->Scrolled('Pane', Name => 'Main Display', -width => 1000, -height =>1000, -background => 'black', -scrollbars => 'osoe', -sticky => 'n', )->pack(-side => "left", -anchor => "n", -fill=>'both',-expand=>1); foreach my $key ( keys %info ){ my $image = $mw->Photo( -data => $info{$key}{'thumbnail'} ); $pane->Label(-image => $image, -background =>'black' )->pack(-side => 'top', -anchor => 'n', -fill => 'both', -expand => 1, ); } } ############################################### sub make_thumbs{ umask 0022; my @pics = ; my $image = Imager->new(); foreach my $pic (@pics){ my ($basename,$path,$suffix) = fileparse($pic,@exts); $info{$basename}{'name'} = $basename; $info{$basename}{'pic'} = "pics/$basename.jpg"; #convert to jpg $image->open(file=>$pic) or die $image->errstr(); # Create smaller version my $temp; my $thumb = $image->scale(xpixels=>100); print "Storing thumbnail: $basename.jpg\n"; $thumb->write(data => \$temp, type =>'jpeg', jpegquality=>30) or die $thumb->errstr; $info{$basename}{'thumbnail'} = encode_base64($temp); } print "\n#########endofthumbcreation#####################\n"; } ############################################### sub save_it{ store(\%info,'notebook.db'); print "saved\n"; exit; } #################################################