* (bug 4207) Wrong image size when using 100x200px syntax to scale image up
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 7 Dec 2005 22:57:22 +0000 (22:57 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 7 Dec 2005 22:57:22 +0000 (22:57 +0000)
  patch by David Benbennick
http://bugzilla.wikimedia.org/attachment.cgi?id=1152

RELEASE-NOTES
includes/Linker.php

index 1c1d990..1dad42f 100644 (file)
@@ -302,6 +302,8 @@ fully support the editing toolbar, but was found to be too confusing.
 * Avoid FATAL ERROR when creating thumbnail of non-existing image
 * (bug 4192) Remove silly 'The Free Encyclopedia' default sitesubtitle
 * (bug 4201) Fix user-talk mode for Enotif, and general code cleanup
+* (bug 4207) Wrong image size when using 100x200px syntax to scale image up
+  patch by David Benbennick
 
 
 === Caveats ===
index 036b2cc..3348c58 100644 (file)
@@ -430,16 +430,19 @@ class Linker {
                        if ( $manual_thumb == '') {
                                $thumb = $img->getThumbnail( $width, $height );
                                if ( $thumb ) {
-                                       if( $width > $img->width && ( $height == -1 || $height > $img->height )) {
-                                               // Requested a display size larger than the actual image;
-                                               // fake it up!
-                                               $height = round($thumb->height * $width / $thumb->width);
-                                               wfDebug( "makeImageLinkObj: client-size height set to '$height'\n" );
-                                       } else {
-                                               $width = $thumb->width;
-                                               $height = $thumb->height;
-                                               wfDebug( "makeImageLinkObj: thumb height set to '$height'\n" );
+                                       // In most cases, $width = $thumb->width or $height = $thumb->height.
+                                       // If not, we're scaling the image larger than it can be scaled,
+                                       // so we send to the browser a smaller thumbnail, and let the client do the scaling.
+
+                                       if ($height != -1 && $width > $thumb->width * $height / $thumb->height) {
+                                               // $height is the limiting factor, not $width
+                                               // set $width to the largest it can be, such that the resulting
+                                               // scaled height is at most $height
+                                               $width = floor($thumb->width * $height / $thumb->height);
                                        }
+                                       $height = round($thumb->height * $width / $thumb->width);
+
+                                       wfDebug( "makeImageLinkObj: client-size set to '$width x $height'\n" );
                                        $url = $thumb->getUrl();
                                }
                        }