Helper methods to query the style's cover photo dimensions
authorAlexander Ebert <ebert@woltlab.com>
Tue, 1 Jun 2021 12:10:45 +0000 (14:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 1 Jun 2021 12:10:45 +0000 (14:10 +0200)
wcfsetup/install/files/lib/data/style/Style.class.php

index c3ad2e4c9600f430477564aebe30d4a9c3f9d662..0fc15e650a749d38a738e92630abe44e099b78cf 100644 (file)
@@ -41,6 +41,16 @@ use wcf\util\ImageUtil;
  */
 class Style extends DatabaseObject
 {
+    /**
+     * @since 5.4
+     */
+    protected $coverPhotoHeight = 0;
+
+    /**
+     * @since 5.4
+     */
+    protected $coverPhotoWidth = 0;
+
     /**
      * @since 5.4
      */
@@ -223,6 +233,15 @@ class Style extends DatabaseObject
                 $this->pageLogoSmallHeight = $data[1];
             }
         }
+
+        $coverPhoto = $this->getCoverPhotoLocation();
+        if (\file_exists($coverPhoto)) {
+            $data = \getimagesize($coverPhoto);
+            if ($data !== false) {
+                $this->coverPhotoWidth = $data[0];
+                $this->coverPhotoHeight = $data[1];
+            }
+        }
     }
 
     /**
@@ -339,6 +358,22 @@ class Style extends DatabaseObject
         return WCF::getPath() . 'images/coverPhotos/' . $this->getCoverPhoto();
     }
 
+    /**
+     * @since 5.4
+     */
+    public function getCoverPhotoHeight(): int
+    {
+        return $this->coverPhotoHeight;
+    }
+
+    /**
+     * @since 5.4
+     */
+    public function getCoverPhotoWidth(): int
+    {
+        return $this->coverPhotoWidth;
+    }
+
     /**
      * @since 5.4
      */