* (bug 3844) ab: av: ba: ce: & kv: now inherit from LanguageRu.php
ii: & za: now inherit from LanguageZn_cn.php
* Optional summary parameter to action=rollback, for user javascript
+* (bug 153) Adjust thumbnail size calculations to match consistently;
+ patch by David Benbennick
=== Caveats ===
* @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.
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 ) {
# 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");
*/
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;
}
# "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 ) {
# 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" );
}
{
// 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
{