Good day Monks. I am trying to use Tk to write an ap that will go through a set of jpgs in a directory, showing them in a window. I would like to scale these pics to fit the window.

I have managed to write code that will step thru and display the jpgs, but I can't quite figure out how to scale them. I think I would use the copy method along with a shrink or zoom argument. But I'm not quite proficient enough with Tk to know how to read in one image, copy it to another resized, then display the second one. Can someone help me out? Existing code is below.

TIA.....Steve

#!/usr/bin/perl -w use strict; use Tk; use Tk::JPEG; my $c; my $dir = "c:/temp"; my @fl = ("01.jpg","05.jpg"); my $main = new MainWindow; nextp(); my $nxt = $main->Button('-text' => "Next", '-command' => \&nextp)->pac +k(); $main->Button(-text => 'exit', -command => sub{destroy $main} )->pack(-anchor => 'e'); MainLoop; sub loadpic { my $filename = shift; my $size; my $orientation; $main -> Photo('img', -file => $filename); my ($h,$w) = ($main->height, $main->width); # # how to scale the pic? # $c = $main->Label('-image' => 'img')->pack; return; } sub nextp { my $f = shift(@fl); loadpic("$dir/$f"); return; }

In reply to Tk sizing a pic to fit a window by cormanaz

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.