Index: trunk/phase3/includes/ImagePage.php |
— | — | @@ -193,15 +193,23 @@ |
194 | 194 | |
195 | 195 | # "Download high res version" link below the image |
196 | 196 | $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) ); |
197 | | - if ( $width > $maxWidth ) { |
198 | | - $height = floor( $height * $maxWidth / $width ); |
199 | | - $width = $maxWidth; |
200 | | - } |
201 | | - if ( $height > $maxHeight ) { |
202 | | - $width = floor( $width * $maxHeight / $height ); |
203 | | - $height = $maxHeight; |
204 | | - } |
205 | | - if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) { |
| 197 | + |
| 198 | + # We'll show a thumbnail of this image |
| 199 | + if ( $width > $maxWidth || $height > $maxHeight ) { |
| 200 | + # Calculate the thumbnail size. |
| 201 | + # First case, the limiting factor is the width, not the height. |
| 202 | + if ( $width / $height >= $maxWidth / $maxHeight ) { |
| 203 | + $height = round( $height * $maxWidth / $width); |
| 204 | + $width = $maxWidth; |
| 205 | + # Note that $height <= $maxHeight now. |
| 206 | + } else { |
| 207 | + $newwidth = floor( $width * $maxHeight / $height); |
| 208 | + $height = round( $height * $newwidth / $width ); |
| 209 | + $width = $newwidth; |
| 210 | + # Note that $height <= $maxHeight now, but might not be identical |
| 211 | + # because of rounding. |
| 212 | + } |
| 213 | + |
206 | 214 | if( $wgUseImageResize ) { |
207 | 215 | $thumbnail = $this->img->getThumbnail( $width ); |
208 | 216 | if ( $thumbnail == null ) { |
Index: trunk/phase3/includes/Linker.php |
— | — | @@ -426,18 +426,18 @@ |
427 | 427 | # Create a resized image, without the additional thumbnail |
428 | 428 | # features |
429 | 429 | |
430 | | - if ( $height !== false && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) { |
431 | | - $width = $img->getWidth() * $height / $img->getHeight(); |
432 | | - } |
| 430 | + if ( $height == false ) |
| 431 | + $height = -1; |
433 | 432 | if ( $manual_thumb == '') { |
434 | | - $thumb = $img->getThumbnail( $width ); |
| 433 | + $thumb = $img->getThumbnail( $width, $height ); |
435 | 434 | if ( $thumb ) { |
436 | | - if( $width > $thumb->width ) { |
| 435 | + if( $width > $img->width && ( $height == -1 || $height > $img->height )) { |
437 | 436 | // Requested a display size larger than the actual image; |
438 | 437 | // fake it up! |
439 | | - $height = floor($thumb->height * $width / $thumb->width); |
| 438 | + $height = round($thumb->height * $width / $thumb->width); |
440 | 439 | wfDebug( "makeImageLinkObj: client-size height set to '$height'\n" ); |
441 | 440 | } else { |
| 441 | + $width = $thumb->width; |
442 | 442 | $height = $thumb->height; |
443 | 443 | wfDebug( "makeImageLinkObj: thumb height set to '$height'\n" ); |
444 | 444 | } |
— | — | @@ -494,20 +494,19 @@ |
495 | 495 | { |
496 | 496 | // Use image dimensions, don't scale |
497 | 497 | $boxwidth = $width; |
498 | | - $oboxwidth = $boxwidth + 2; |
499 | 498 | $boxheight = $height; |
500 | 499 | $thumbUrl = $url; |
501 | 500 | } else { |
502 | | - $h = round( $height/($width/$boxwidth) ); |
503 | | - $oboxwidth = $boxwidth + 2; |
504 | | - if ( ( ! $boxheight === false ) && ( $h > $boxheight ) ) |
505 | | - { |
506 | | - $boxwidth *= $boxheight/$h; |
507 | | - } else { |
508 | | - $boxheight = $h; |
| 501 | + if ( $boxheight === false ) |
| 502 | + $boxheight = -1; |
| 503 | + if ( '' == $manual_thumb ) { |
| 504 | + $thumb = $img->getThumbnail( $boxwidth, $boxheight ); |
| 505 | + $thumbUrl = $thumb->getUrl(); |
| 506 | + $boxwidth = $thumb->width; |
| 507 | + $boxheight = $thumb->height; |
509 | 508 | } |
510 | | - if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth ); |
511 | 509 | } |
| 510 | + $oboxwidth = $boxwidth + 2; |
512 | 511 | |
513 | 512 | if ( $manual_thumb != '' ) # Use manually specified thumbnail |
514 | 513 | { |
Index: trunk/phase3/includes/Image.php |
— | — | @@ -859,25 +859,18 @@ |
860 | 860 | * @access public |
861 | 861 | */ |
862 | 862 | function getThumbnail( $width, $height=-1 ) { |
863 | | - if ( $height == -1 ) { |
| 863 | + if ( $height <= 0 ) { |
864 | 864 | return $this->renderThumb( $width ); |
865 | 865 | } |
866 | 866 | $this->load(); |
867 | 867 | |
868 | 868 | if ($this->canRender()) { |
869 | | - if ( $width < $this->width ) { |
870 | | - $thumbheight = $this->height * $width / $this->width; |
871 | | - $thumbwidth = $width; |
872 | | - } else { |
873 | | - $thumbheight = $this->height; |
874 | | - $thumbwidth = $this->width; |
875 | | - } |
876 | | - if ( $thumbheight > $height ) { |
877 | | - $thumbwidth = $thumbwidth * $height / $thumbheight; |
878 | | - $thumbheight = $height; |
879 | | - } |
880 | | - |
881 | | - $thumb = $this->renderThumb( $thumbwidth ); |
| 869 | + if ( $width > $this->width * $height / $this->height ) |
| 870 | + $width = floor( $this->width * $height / $this->height ); |
| 871 | + # Note this is the largest width such that the thumbnail's |
| 872 | + # height is at most $height. |
| 873 | + |
| 874 | + $thumb = $this->renderThumb( $width ); |
882 | 875 | } |
883 | 876 | else $thumb= NULL; #not a bitmap or renderable image, don't try. |
884 | 877 | |
— | — | @@ -962,7 +955,7 @@ |
963 | 956 | return $thumb; |
964 | 957 | } |
965 | 958 | |
966 | | - $height = floor( $this->height * ( $width/$this->width ) ); |
| 959 | + $height = round( $this->height * $width / $this->width ); |
967 | 960 | |
968 | 961 | list( $isScriptUrl, $url ) = $this->thumbUrl( $width ); |
969 | 962 | if ( $isScriptUrl && $useScript ) { |
— | — | @@ -1046,8 +1039,12 @@ |
1047 | 1040 | # use ImageMagick |
1048 | 1041 | # Specify white background color, will be used for transparent images |
1049 | 1042 | # in Internet Explorer/Windows instead of default black. |
| 1043 | + |
| 1044 | + # Note, we specify "-size {$width}" and NOT "-size {$width}x{$height}". |
| 1045 | + # It seems that ImageMagick has a bug wherein it produces thumbnails of |
| 1046 | + # the wrong size in the second case. |
1050 | 1047 | $cmd = $wgImageMagickConvertCommand . |
1051 | | - " -quality 85 -background white -size {$width}x{$height} ". |
| 1048 | + " -quality 85 -background white -size {$width} ". |
1052 | 1049 | wfEscapeShellArg($this->imagePath) . " -resize {$width}x{$height} " . |
1053 | 1050 | wfEscapeShellArg($thumbPath); |
1054 | 1051 | wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n"); |
— | — | @@ -1800,8 +1797,11 @@ |
1801 | 1798 | */ |
1802 | 1799 | function ThumbnailImage( $url, $width, $height, $path = false ) { |
1803 | 1800 | $this->url = $url; |
1804 | | - $this->width = $width; |
1805 | | - $this->height = $height; |
| 1801 | + $this->width = round( $width ); |
| 1802 | + $this->height = round( $height ); |
| 1803 | + # These should be integers when they get here. |
| 1804 | + # If not, there's a bug somewhere. But let's at |
| 1805 | + # least produce valid HTML code regardless. |
1806 | 1806 | $this->path = $path; |
1807 | 1807 | } |
1808 | 1808 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -287,6 +287,8 @@ |
288 | 288 | * (bug 3844) ab: av: ba: ce: & kv: now inherit from LanguageRu.php |
289 | 289 | ii: & za: now inherit from LanguageZn_cn.php |
290 | 290 | * Optional summary parameter to action=rollback, for user javascript |
| 291 | +* (bug 153) Adjust thumbnail size calculations to match consistently; |
| 292 | + patch by David Benbennick |
291 | 293 | |
292 | 294 | |
293 | 295 | === Caveats === |