BUG#1218 - Show the original image on image pages if the thumbnail would be bigger...
authorJens Frank <jeluf@users.mediawiki.org>
Tue, 28 Dec 2004 12:31:33 +0000 (12:31 +0000)
committerJens Frank <jeluf@users.mediawiki.org>
Tue, 28 Dec 2004 12:31:33 +0000 (12:31 +0000)
includes/Image.php
includes/ImagePage.php

index 51cbf29..59f91b8 100644 (file)
@@ -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;                }                       
+        }
+
 }
 
 ?>
index 9f86022..ba594ac 100644 (file)
@@ -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 "<pre>thumb ". $thumbnail->getSize() ."\nimg  ".$this->img->getSize()."</pre>";
+                                               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.