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 ); } }

In reply to Memory issue while experimenting with Tk::Thumbnail by atcroft

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.