Using `Image::Imlib2' means that we don't learn the size without fully
decoding the image and using up lots of memory. The `Image::Size'
package will determine the image size by reading it out of the file
without decoding, so it's much faster.
Of course, that doesn't matter much yet, because we're only using it
/after/ we decode the image. Hmm...
use File::stat;
use Image::ExifTool qw{};
use Image::Imlib2;
use File::stat;
use Image::ExifTool qw{};
use Image::Imlib2;
use User::pwent;
use POSIX;
use User::pwent;
use POSIX;
return bless {
path => $path, imgpath => $imgpath,
mtime => $st->mtime,
return bless {
path => $path, imgpath => $imgpath,
mtime => $st->mtime,
+ img => undef,
+ _wd => undef, _ht => undef,
+ sz => undef
+ sub _getsz ($) {
+ my ($me) = @_;
+ return if defined $me->{_wd};
+
+ my ($wd, $ht, $err) = Image::Size::imgsize $me->{imgpath};
+ defined $wd or die "failed to read size of `$me->{path}': $err";
+ my $sz = $wd; if ($sz < $ht) { $sz = $ht; }
+ @$me{"_wd", "_ht", "sz"} = ($wd, $ht, $sz);
+ }
+
+ sub sz ($) { my ($me) = @_; $me->_getsz; return $me->{sz}; }
+
sub scale ($$;$) {
my ($me, $scale, $forcep) = @_;
my $m = HTML::Mason::Request->instance;
sub scale ($$;$) {
my ($me, $scale, $forcep) = @_;
my $m = HTML::Mason::Request->instance;
- my ($wd, $ht) = ($img->width, $img->height);
- my $max = $wd > $ht ? $wd : $ht;
- if ($max <= $sz)
{ return $m->interp->apply_escapes("$IMGURL/$path", "u"); }
{ return $m->interp->apply_escapes("$IMGURL/$path", "u"); }
my $scaled = $img->create_scaled_image($sc*$wd, $sc*$ht);
$scaled->image_set_format($ty->imlibfmt);
my $scaled = $img->create_scaled_image($sc*$wd, $sc*$ht);
$scaled->image_set_format($ty->imlibfmt);