From 039650c45610ac4d0813061e7c9647c44f6750a2 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Tue, 28 Dec 2004 12:31:33 +0000 Subject: [PATCH] BUG#1218 - Show the original image on image pages if the thumbnail would be bigger than the original image --- includes/Image.php | 16 +++++++++++++++- includes/ImagePage.php | 13 ++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/includes/Image.php b/includes/Image.php index 51cbf29fa2..59f91b8e34 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -506,7 +506,7 @@ class Image # Check for zero-sized thumbnails. Those can be generated when # no disk space is available or some other error occurs # - if( file_exists( $thumbstat ) ) { + if( file_exists( $thumbPath ) ) { $thumbstat = stat( $thumbPath ); if( $thumbstat['size'] == 0 ) { unlink( $thumbPath ); @@ -979,6 +979,20 @@ class ThumbnailImage { $html .= '/>'; return $html; } + + /** + * Return the size of the thumbnail file, in bytes + * @access public + */ + function getSize() + { + $st = stat( $this->path ); + if( $st ) { + return $st['size']; + } else { + return false; } + } + } ?> diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 9f86022fbc..ba594accac 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -79,7 +79,18 @@ class ImagePage extends Article { } if ( $width != $this->img->getWidth() || $height != $this->img->getHeight() ) { if( $wgUseImageResize ) { - $url = $this->img->createThumb( $width ); + $thumbnail = $this->img->getThumbnail( $width ); + print "
thumb ". $thumbnail->getSize() ."\nimg  ".$this->img->getSize()."
"; + if ( ( ! $this->img->mustRender() ) + && ( $thumbnail->getSize() > $this->img->getSize() ) ) { + # the thumbnail is bigger thatn the original image. + # show the original image instead of the thumb. + $url = $full_url; + $width = $this->img->getWidth(); + $height = $this->img->getHeight(); + } else { + $url = $thumbnail->getUrl(); + } } else { # No resize ability? Show the full image, but scale # it down in the browser so it fits on the page. -- 2.20.1