From: Joey Hess Date: Sat, 29 Aug 2009 03:44:49 +0000 (-0400) Subject: img: Don't generate new verison of image if it is scaled to be larger in either dimen... X-Git-Tag: 2.53.4~3 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/a4afb333a56500f3755e1f2de9ce31fcc5165405 img: Don't generate new verison of image if it is scaled to be larger in either dimension. Although imagemagick handles even really large sizes sanely, using a page file, doing so would just waste time and disk space, since the browser can be told to resize it larger. Conflicts: IkiWiki/Plugin/img.pm debian/changelog --- diff --git a/IkiWiki/Plugin/img.pm b/IkiWiki/Plugin/img.pm index cc0e84b01..e99c9b869 100644 --- a/IkiWiki/Plugin/img.pm +++ b/IkiWiki/Plugin/img.pm @@ -51,6 +51,8 @@ sub preprocess (@) { #{{{ my $imglink; my $r; + my ($dwidth, $dheight); + if ($params{size} ne 'full') { my ($w, $h) = ($params{size} =~ /^(\d+)x(\d+)$/); return "[[img ".sprintf(gettext('bad size "%s"'), $params{size})."]]" @@ -69,7 +71,15 @@ sub preprocess (@) { #{{{ $r = $im->Read(srcfile($file)); return "[[img ".sprintf(gettext("failed to read %s: %s"), $file, $r)."]]" if $r; - $r = $im->Resize(geometry => "${w}x${h}"); + # don't resize any larger + my ($rw, $rh) = ($w, $h); + if ($rw > $im->Get("width") || + $rh > $im->Get("height")) { + $rw=$im->Get("width"); + $rh=$im->Get("height"); + } + + $r = $im->Resize(geometry => "${rw}x${rh}"); return "[[img ".sprintf(gettext("failed to resize: %s"), $r)."]]" if $r; # don't actually write file in preview mode @@ -81,11 +91,17 @@ sub preprocess (@) { #{{{ $imglink = $file; } } + + # since we don't really resize larger, set the display + # size, so the browser can scale the image up if necessary + ($dwidth, $dheight)=($w, $h); } else { $r = $im->Read(srcfile($file)); return "[[img ".sprintf(gettext("failed to read %s: %s"), $file, $r)."]]" if $r; $imglink = $file; + $dwidth = $im->Get("width"); + $dheight = $im->Get("height"); } add_depends($imglink, $params{page}); @@ -106,8 +122,8 @@ sub preprocess (@) { #{{{ my $imgtag=''.(exists $params{alt} ? $params{alt} : '').
-		' Fri, 28 Aug 2009 23:42:51 -0400 + ikiwiki (2.53.3) testing-proposed-updates; urgency=low * Avoid crash on malformed utf-8 discovered by intrigeri.