atcroft has asked for the wisdom of the Perl Monks concerning the following question:
I was experimenting with code (below the READMORE tag) that would seek the images present in a subdirectory or subdirectories and present them using Tk::Thumbnail, and have encountered quite the problem. When I run it on a directory tree containing of 20-30 JPEGS (900x1200 or 1600x1200, approximately 400-500KB in size each), no issues; however, when I run it against a directory tree containing 100-150 similar images, it locks my machine because of a lack of memory (512MB RAM, and approximately the same for swap space). I suspect it is in part because of the processing to create the thumbnails (and considered trying to use other means, such as Image::GD::Thumbnail, but no joy).
Any suggestions/assistance appreciated.
#!/usr/bin/perl -w use strict; use vars qw($ft @filelist @typelist); use File::Find; use File::Glob qw(:glob); use File::Type; use GD; use Image::GD::Thumbnail; use Image::Size; use Tk; use Tk::JPEG; use Tk::PNG; use Tk::TIFF; use Tk::Thumbnail; use Tk::Stderr; $| = 1; my (@directories_to_search); foreach my $dir ( ( scalar(@ARGV) > 0 ? @ARGV : '.' ) ) { push( @directories_to_search, bsd_glob( $dir, GLOB_TILDE | GLOB_ERR ) ); } print join( "\n", @directories_to_search ), "\n\n"; $ft = File::Type->new(); find( { wanted => \&wanted, follow_skip => 2, no_chdir => 1 }, @directories_to_search ); print "\n"; my (%images); { my @templist = sort { $a cmp $b } @filelist; @filelist = @templist; } my $mw = MainWindow->new(); my $stderrw = MainWindow->new->InitStderr; $mw->title($0); { my (@imagelist); foreach ( 0 .. $#filelist ) { print $filelist[$_], "\n"; my $temp = $mw->Photo( -file => $filelist[$_] ); push( @imagelist, $temp ); } eval { my $thumb = $mw->Thumbnail( -images => [@imagelist], -ilabels => 1 )->pack; }; warn($@) if ($@); } MainLoop; sub wanted { return unless ( -R $File::Find::dir ); return unless ( defined($File::Find::name) ); return unless ( -f $File::Find::name ); return unless ( -R $File::Find::name ); my ($type_from_file); eval { $type_from_file = $ft->checktype_filename($File::Find::name); printf "Unknown type: %s\n", $File::Find::name unless ( defined($type_from_file) ); }; return unless ( defined($type_from_file) ); if ( $type_from_file =~ m/image/ ) { push( @filelist, $File::Find::name ); push( @typelist, $type_from_file ); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Memory issue while experimenting with Tk::Thumbnail
by SciDude (Friar) on May 30, 2004 at 00:49 UTC | |
|
Re: Memory issue while experimenting with Tk::Thumbnail
by zentara (Cardinal) on May 30, 2004 at 14:14 UTC | |
|
Re: Memory issue while experimenting with Tk::Thumbnail
by andyf (Pilgrim) on May 30, 2004 at 13:36 UTC | |
|
Re: Memory issue while experimenting with Tk::Thumbnail
by zentara (Cardinal) on May 30, 2004 at 19:13 UTC |