I'm working with ActivePerl build 810 on an XP box. I want to resize a large image so that it will fit on the screen, with a little resampling, and then show it in a Tk::Label.
$imgfile and $imgwidth are the file containing the image and the width to resize it to. $display is the Tk::Photo that contains the on-screen image. My first go worked fine:
sub rerender {
`i_view32.exe .\\$imgfile /resample=($imgwidth,) /aspectratio /convert=".\\disp.png"`;
$display->configure(-file => 'disp.png');
}
This uses an external program (irfanview) to do the dirty work, saves the downsized image to a temp file, and then reads it into the Tk::Photo. Thinking it could be faster w/o writing and readign the temp file, I did this using the Image::Magick module:
sub rerender {
my $image = Image::Magick->new();
$image->Read($imgfile);
$image->Resize(width => $imgwidth, height => $imgwidth * 1.5, filter => Box);
my $blob = $image->ImageToBlob();
$display->configure(-format => 'png', -data => encode_base64($blob));
}
Which also works, but takes twice as long as the first version. Where do you think the time being spent? How could the image be produced and displayed any faster?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.