r11944 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r11943‎ | r11944 | r11945 >
Date:08:52, 4 December 2005
Author:vibber
Status:old
Tags:
Comment:
* (bug 153) Adjust thumbnail size calculations to match consistently;
patch by David Benbennick
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Image.php (modified) (history)
  • /trunk/phase3/includes/ImagePage.php (modified) (history)
  • /trunk/phase3/includes/Linker.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ImagePage.php
@@ -193,15 +193,23 @@
194194
195195 # "Download high res version" link below the image
196196 $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+
206214 if( $wgUseImageResize ) {
207215 $thumbnail = $this->img->getThumbnail( $width );
208216 if ( $thumbnail == null ) {
Index: trunk/phase3/includes/Linker.php
@@ -426,18 +426,18 @@
427427 # Create a resized image, without the additional thumbnail
428428 # features
429429
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;
433432 if ( $manual_thumb == '') {
434 - $thumb = $img->getThumbnail( $width );
 433+ $thumb = $img->getThumbnail( $width, $height );
435434 if ( $thumb ) {
436 - if( $width > $thumb->width ) {
 435+ if( $width > $img->width && ( $height == -1 || $height > $img->height )) {
437436 // Requested a display size larger than the actual image;
438437 // fake it up!
439 - $height = floor($thumb->height * $width / $thumb->width);
 438+ $height = round($thumb->height * $width / $thumb->width);
440439 wfDebug( "makeImageLinkObj: client-size height set to '$height'\n" );
441440 } else {
 441+ $width = $thumb->width;
442442 $height = $thumb->height;
443443 wfDebug( "makeImageLinkObj: thumb height set to '$height'\n" );
444444 }
@@ -494,20 +494,19 @@
495495 {
496496 // Use image dimensions, don't scale
497497 $boxwidth = $width;
498 - $oboxwidth = $boxwidth + 2;
499498 $boxheight = $height;
500499 $thumbUrl = $url;
501500 } 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;
509508 }
510 - if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
511509 }
 510+ $oboxwidth = $boxwidth + 2;
512511
513512 if ( $manual_thumb != '' ) # Use manually specified thumbnail
514513 {
Index: trunk/phase3/includes/Image.php
@@ -859,25 +859,18 @@
860860 * @access public
861861 */
862862 function getThumbnail( $width, $height=-1 ) {
863 - if ( $height == -1 ) {
 863+ if ( $height <= 0 ) {
864864 return $this->renderThumb( $width );
865865 }
866866 $this->load();
867867
868868 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 );
882875 }
883876 else $thumb= NULL; #not a bitmap or renderable image, don't try.
884877
@@ -962,7 +955,7 @@
963956 return $thumb;
964957 }
965958
966 - $height = floor( $this->height * ( $width/$this->width ) );
 959+ $height = round( $this->height * $width / $this->width );
967960
968961 list( $isScriptUrl, $url ) = $this->thumbUrl( $width );
969962 if ( $isScriptUrl && $useScript ) {
@@ -1046,8 +1039,12 @@
10471040 # use ImageMagick
10481041 # Specify white background color, will be used for transparent images
10491042 # 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.
10501047 $cmd = $wgImageMagickConvertCommand .
1051 - " -quality 85 -background white -size {$width}x{$height} ".
 1048+ " -quality 85 -background white -size {$width} ".
10521049 wfEscapeShellArg($this->imagePath) . " -resize {$width}x{$height} " .
10531050 wfEscapeShellArg($thumbPath);
10541051 wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n");
@@ -1800,8 +1797,11 @@
18011798 */
18021799 function ThumbnailImage( $url, $width, $height, $path = false ) {
18031800 $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.
18061806 $this->path = $path;
18071807 }
18081808
Index: trunk/phase3/RELEASE-NOTES
@@ -287,6 +287,8 @@
288288 * (bug 3844) ab: av: ba: ce: & kv: now inherit from LanguageRu.php
289289 ii: & za: now inherit from LanguageZn_cn.php
290290 * Optional summary parameter to action=rollback, for user javascript
 291+* (bug 153) Adjust thumbnail size calculations to match consistently;
 292+ patch by David Benbennick
291293
292294
293295 === Caveats ===

Follow-up revisions

RevisionCommit summaryAuthorDate
r11974* (bug 4167) Fix regression caused by patch for bug 153...vibber06:14, 5 December 2005

Status & tagging log