Index: includes/Image.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/Image.php,v retrieving revision 1.129 diff -u -r1.129 Image.php --- includes/Image.php 19 Sep 2005 12:53:49 -0000 1.129 +++ includes/Image.php 26 Sep 2005 10:09:55 -0000 @@ -860,25 +860,18 @@ * @access public */ function getThumbnail( $width, $height=-1 ) { - if ( $height == -1 ) { + if ( $height <= 0 ) { return $this->renderThumb( $width ); } $this->load(); if ($this->canRender()) { - if ( $width < $this->width ) { - $thumbheight = $this->height * $width / $this->width; - $thumbwidth = $width; - } else { - $thumbheight = $this->height; - $thumbwidth = $this->width; - } - if ( $thumbheight > $height ) { - $thumbwidth = $thumbwidth * $height / $thumbheight; - $thumbheight = $height; - } - - $thumb = $this->renderThumb( $thumbwidth ); + if ( $width > $this->width * $height / $this->height ) + $width = floor( $this->width * $height / $this->height ); + # Note this is the largest width such that the thumbnail's + # height is at most $height. + + $thumb = $this->renderThumb( $width ); } else $thumb= NULL; #not a bitmap or renderable image, don't try. @@ -952,7 +945,7 @@ return $thumb; } - $height = floor( $this->height * ( $width/$this->width ) ); + $height = round( $this->height * $width / $this->width ); list( $isScriptUrl, $url ) = $this->thumbUrl( $width ); if ( $isScriptUrl && $useScript ) { @@ -1034,8 +1027,12 @@ # use ImageMagick # Specify white background color, will be used for transparent images # in Internet Explorer/Windows instead of default black. + + # Note, we specify "-size {$width}" and NOT "-size {$width}x{$height}". + # It seems that ImageMagick has a bug wherein it produces thumbnails of + # the wrong size in the second case. $cmd = $wgImageMagickConvertCommand . - " -quality 85 -background white -size {$width}x{$height} ". + " -quality 85 -background white -size {$width} ". wfEscapeShellArg($this->imagePath) . " -resize {$width}x{$height} " . wfEscapeShellArg($thumbPath); wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n"); @@ -1789,8 +1786,11 @@ */ function ThumbnailImage( $url, $width, $height, $path = false ) { $this->url = $url; - $this->width = $width; - $this->height = $height; + $this->width = round( $width ); + $this->height = round( $height ); + # These should be integers when they get here. + # If not, there's a bug somewhere. But let's at + # least produce valid HTML code regardless. $this->path = $path; } Index: includes/ImagePage.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/ImagePage.php,v retrieving revision 1.119 diff -u -r1.119 ImagePage.php --- includes/ImagePage.php 20 Sep 2005 18:03:08 -0000 1.119 +++ includes/ImagePage.php 26 Sep 2005 10:09:56 -0000 @@ -162,15 +162,23 @@ # "Download high res version" link below the image $msg = wfMsgHtml('showbigimage', $width, $height, intval( $this->img->getSize()/1024 ) ); - if ( $width > $maxWidth ) { - $height = floor( $height * $maxWidth / $width ); - $width = $maxWidth; - } - if ( $height > $maxHeight ) { - $width = floor( $width * $maxHeight / $height ); - $height = $maxHeight; - } - if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) { + + # We'll show a thumbnail of this image + if ( $width > $maxWidth || $height > $maxHeight ) { + # Calculate the thumbnail size. + # First case, the limiting factor is the width, not the height. + if ( $width / $height >= $maxWidth / $maxHeight ) { + $height = round( $height * $maxWidth / $width); + $width = $maxWidth; + # Note that $height <= $maxHeight now. + } else { + $newwidth = floor( $width * $maxHeight / $height); + $height = round( $height * $newwidth / $width ); + $width = $newwidth; + # Note that $height <= $maxHeight now, but might not be identical + # because of rounding. + } + if( $wgUseImageResize ) { $thumbnail = $this->img->getThumbnail( $width ); if ( $thumbnail == null ) { Index: includes/Linker.php =================================================================== RCS file: /cvsroot/wikipedia/phase3/includes/Linker.php,v retrieving revision 1.49 diff -u -r1.49 Linker.php --- includes/Linker.php 12 Sep 2005 22:46:13 -0000 1.49 +++ includes/Linker.php 26 Sep 2005 10:09:56 -0000 @@ -426,18 +426,18 @@ # Create a resized image, without the additional thumbnail # features - if ( $height !== false && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) { - $width = $img->getWidth() * $height / $img->getHeight(); - } + if ( $height == false ) + $height = -1; if ( $manual_thumb == '') { - $thumb = $img->getThumbnail( $width ); + $thumb = $img->getThumbnail( $width, $height ); if ( $thumb ) { - if( $width > $thumb->width ) { + if( $width > $img->width && ( $height == -1 || $height > $img->height )) { // Requested a display size larger than the actual image; // fake it up! - $height = floor($thumb->height * $width / $thumb->width); + $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" ); } @@ -494,20 +494,19 @@ { // Use image dimensions, don't scale $boxwidth = $width; - $oboxwidth = $boxwidth + 2; $boxheight = $height; $thumbUrl = $url; } else { - $h = round( $height/($width/$boxwidth) ); - $oboxwidth = $boxwidth + 2; - if ( ( ! $boxheight === false ) && ( $h > $boxheight ) ) - { - $boxwidth *= $boxheight/$h; - } else { - $boxheight = $h; + if ( $boxheight === false ) + $boxheight = -1; + if ( '' == $manual_thumb ) { + $thumb = $img->getThumbnail( $boxwidth, $boxheight ); + $thumbUrl = $thumb->getUrl(); + $boxwidth = $thumb->width; + $boxheight = $thumb->height; } - if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth ); } + $oboxwidth = $boxwidth + 2; if ( $manual_thumb != '' ) # Use manually specified thumbnail {