From: Mark Wooding Date: Tue, 20 Jun 2023 20:19:09 +0000 (+0100) Subject: mason/.perl-lib/TrivGal.pm (Image::scale): Check size much earlier. X-Git-Url: https://git.distorted.org.uk/~mdw/tgal/commitdiff_plain/373818eb967dad9061b829700c1368835a5ba589 mason/.perl-lib/TrivGal.pm (Image::scale): Check size much earlier. We check whether the original image is small enough to be used as-is rather than making a scaled-down version, but currently we do that very late, when we're actually about to try scaling it. That's obviously a bad idea. Instead, check early now that we have a library that can find an image's size without costly decoding. In particular, this is now done /before/ we decide whether to hand off via the `?scale=...' lazy thumbnailer, which is important because, in the case where the image is small, we'll never actually make the thumbnail and we'll always pay the redirection penalty. This will actually slow down handling of large images; but they're kinda inevitably a bit slow. Besides, `Image::Size' is surprisingly fast. --- diff --git a/mason/.perl-lib/TrivGal.pm b/mason/.perl-lib/TrivGal.pm index d6d3afb..513a682 100644 --- a/mason/.perl-lib/TrivGal.pm +++ b/mason/.perl-lib/TrivGal.pm @@ -240,6 +240,9 @@ package TrivGal::Image { my $path = $me->{path}; my $sz = $SIZE{$scale} or die "unknown scale `$scale'"; + if ($me->sz <= $sz) + { return $m->interp->apply_escapes("$IMGURL/$path", "u"); } + my $thumb = "$CACHE/scale.$sz/$path"; my $thumburl = $m->interp->apply_escapes("$CACHEURL/scale.$sz/$path", "u"); @@ -265,8 +268,6 @@ package TrivGal::Image { } } - if ($me->sz <= $sz) - { return $m->interp->apply_escapes("$IMGURL/$path", "u"); } my $sc = $sz/$me->sz; my $scaled = $img->create_scaled_image($sc*$wd, $sc*$ht);