displaying an image
shimmin
created: 2004-07-01 11:05:14
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?
Re: displaying an image
created: 2004-07-01 11:21:28

How about caching each resized image as a file whose name or path encodes the size? That way the expensive stuff only needs to be done once.

After Compline,
Zaxo

perlmonks.org content © perlmonks.org and shimmin, Zaxo

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03