Fix the dimension check for images w/o thumbnail
authorAlexander Ebert <ebert@woltlab.com>
Fri, 8 Sep 2023 15:22:01 +0000 (17:22 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 8 Sep 2023 15:22:01 +0000 (17:22 +0200)
See https://www.woltlab.com/community/thread/301523-bilder-die-zu-klein-f%C3%BCr-eine-vorschau-sind-aber-gro%C3%9F-genug-f%C3%BCr-den-bildbetrachte/

wcfsetup/install/files/lib/data/attachment/Attachment.class.php

index b0e63e62f561acae843745f0b0add38dcd0183f6..6da89e0e84bdce018cfa34484aea395272b62da9 100644 (file)
@@ -190,13 +190,11 @@ class Attachment extends DatabaseObject implements ILinkableObject, IRouteContro
      */
     public function migrateStorage()
     {
-        foreach (
-            [
-                $this->getLocation(),
-                $this->getThumbnailLocation(),
-                $this->getThumbnailLocation('tiny'),
-            ] as $location
-        ) {
+        foreach ([
+            $this->getLocation(),
+            $this->getThumbnailLocation(),
+            $this->getThumbnailLocation('tiny'),
+        ] as $location) {
             if (!\str_ends_with($location, '.bin')) {
                 \rename($location, $location . '.bin');
             }
@@ -277,8 +275,21 @@ class Attachment extends DatabaseObject implements ILinkableObject, IRouteContro
     public function showAsImage()
     {
         if ($this->isImage) {
-            if (!$this->hasThumbnail() && ($this->width > ATTACHMENT_THUMBNAIL_WIDTH || $this->height > ATTACHMENT_THUMBNAIL_HEIGHT)) {
-                return false;
+            if (!$this->hasThumbnail() && ($this->width > \ATTACHMENT_THUMBNAIL_WIDTH || $this->height > \ATTACHMENT_THUMBNAIL_HEIGHT)) {
+                // Some images have no thumbnail because this is not really an
+                // image or it is unrecognized. However, there are images that
+                // do not have a thumbnail because one of its dimensions is
+                // less then the thumbnails minimum of that side.
+                $shouldHaveThumbnail = true;
+                if ($this->width > \ATTACHMENT_THUMBNAIL_WIDTH && $this->height < \ATTACHMENT_THUMBNAIL_HEIGHT) {
+                    $shouldHaveThumbnail = false;
+                } else if ($this->height > ATTACHMENT_THUMBNAIL_HEIGHT && $this->width < \ATTACHMENT_THUMBNAIL_WIDTH) {
+                    $shouldHaveThumbnail = false;
+                }
+
+                if ($shouldHaveThumbnail) {
+                    return false;
+                }
             }
 
             if ($this->canDownload()) {