]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
img: Don't generate new verison of image if it is scaled to be larger in either dimen...
authorJoey Hess <joey@gnu.kitenet.net>
Sat, 29 Aug 2009 03:44:49 +0000 (23:44 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Sat, 29 Aug 2009 04:11:34 +0000 (00:11 -0400)
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

IkiWiki/Plugin/img.pm
debian/changelog

index cc0e84b01f09a7527c341a99c8262eeebb34d106..e99c9b8690bac037b9ad4447f830b707757652b0 100644 (file)
@@ -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='<img src="'.$imgurl.
                '" alt="'.(exists $params{alt} ? $params{alt} : '').
-               '" width="'.$im->Get("width").
-               '" height="'.$im->Get("height").'"'.
+               '" width="'.$dwidth.
+               '" height="'.$dheight.'"'.
                (exists $params{title} ? ' title="'.$params{title}.'"' : '').
                (exists $params{class} ? ' class="'.$params{class}.'"' : '').
                (exists $params{id} ? ' id="'.$params{id}.'"' : '').
index c4b3a1edc7c0746eee5bec09bdddc6c61accc499..72650f199bf04d2762c7a9ba2335f5a09baacb07 100644 (file)
@@ -1,3 +1,10 @@
+ikiwiki (2.53.4) UNRELEASED; urgency=low
+
+  * img: Don't generate new verison of image if it is scaled to be
+    larger in either dimension. 
+
+ -- Joey Hess <joeyh@debian.org>  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.