+ 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 _getexif ($) {
+ my ($me) = @_;
+ return if defined $me->{wd};
+
+ $me->_getsz;
+ my $exif = new Image::ExifTool; $exif->ExtractInfo($me->{imgpath});
+ my $orient = $exif->GetValue("Orientation", "ValueConv");
+ my ($wd, $ht) = @$me{"_wd", "_ht"};
+ my ($rot, $flip);
+ if (defined $orient) { ($rot, $flip) = $ORIENT{$orient}->@*; }
+ else { ($rot, $flip) = (0, 0); }
+ if ($rot%2) { ($wd, $ht) = ($ht, $wd); }
+ @$me{"rot", "flip", "wd", "ht"} = ($rot, $flip, $wd, $ht);
+ }
+
+ sub sz ($) { my ($me) = @_; $me->_getsz; return $me->{sz}; }
+ sub wd ($) { my ($me) = @_; $me->_getexif; return $me->{wd}; }
+ sub ht ($) { my ($me) = @_; $me->_getexif; return $me->{ht}; }
+
+ sub _check_gm ($) {
+ my ($rc) = @_;
+ "$rc" and die "failed to hack `$me->{img}': $rc";
+ }
+
+ sub scale ($$;$) {
+ my ($me, $scale, $forcep) = @_;
+ my $m = HTML::Mason::Request->instance;