Added methods to get the dimensions of a thumbnail
authorMarcel Werk <burntime@woltlab.com>
Sun, 19 Jun 2016 22:00:38 +0000 (00:00 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 19 Jun 2016 22:00:38 +0000 (00:00 +0200)
wcfsetup/install/files/lib/data/media/Media.class.php
wcfsetup/install/files/lib/data/media/ViewableMedia.class.php

index f20ba89e983ae8fd924c6b5e2903084912409185..0e6e933b2f1b4b1e021ac4e72abcc2fd1bf451e0 100644 (file)
@@ -116,6 +116,10 @@ class Media extends DatabaseObject implements ILinkableObject, IRouteController,
                        throw new SystemException("Unknown thumbnail size '".$size."'");
                }
                
+               if (!$this->{$size.'ThumbnailType'}) {
+                       return $this->getLink();
+               }
+               
                return LinkHandler::getInstance()->getLink('Media', [
                        'forceFrontend' => true,
                        'object' => $this,
@@ -123,6 +127,44 @@ class Media extends DatabaseObject implements ILinkableObject, IRouteController,
                ]);
        }
        
+       /**
+        * Returns the width of the thumbnail file with the given size.
+        *
+        * @param       string          $size
+        * @return      integer
+        * @throws      SystemException
+        */
+       public function getThumbnailWidth($size) {
+               if (!isset(self::$thumbnailSizes[$size])) {
+                       throw new SystemException("Unknown thumbnail size '".$size."'");
+               }
+               
+               if ($this->{$size.'ThumbnailType'}) {
+                       return $this->{$size.'ThumbnailWidth'};
+               }
+               
+               return $this->width;
+       }
+       
+       /**
+        * Returns the height of the thumbnail file with the given size.
+        *
+        * @param       string          $size
+        * @return      integer
+        * @throws      SystemException
+        */
+       public function getThumbnailHeight($size) {
+               if (!isset(self::$thumbnailSizes[$size])) {
+                       throw new SystemException("Unknown thumbnail size '".$size."'");
+               }
+               
+               if ($this->{$size.'ThumbnailType'}) {
+                       return $this->{$size.'ThumbnailHeight'};
+               }
+               
+               return $this->height;
+       }
+       
        /**
         * @inheritDoc
         */
index c621f1b311e54de9b7eb62aeec5db4301a16610c..af180a81322b30f8034f17c78592d650c491a50f 100644 (file)
@@ -68,7 +68,7 @@ class ViewableMedia extends DatabaseObjectDecorator {
                        throw new SystemException("Unknown thumbnail size '".$size."'");
                }
                
-               return '<img src="'.$this->getThumbnailLink($size).'" alt="'.StringUtil::encodeHTML($this->altText).'" '.($this->title ? 'title="'.StringUtil::encodeHTML($this->title).'" ' : '').'/>';
+               return '<img src="'.$this->getThumbnailLink($size).'" alt="'.StringUtil::encodeHTML($this->altText).'" '.($this->title ? 'title="'.StringUtil::encodeHTML($this->title).'" ' : '').'style="width: ' . $this->getThumbnailWidth($size) . 'px; height: ' . $this->getThumbnailHeight($size) . 'px;">';
        }
        
        /**