From 0b37b9e0def302adbece3a165bcbc0935d4d14d0 Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Tue, 12 Nov 2024 21:06:33 -0700 Subject: [PATCH] Use poster for thumbnail Signed-off-by: Justin Georgi --- includes/GlModelTransformOutput.php | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/includes/GlModelTransformOutput.php b/includes/GlModelTransformOutput.php index 46ba449..b5c8068 100644 --- a/includes/GlModelTransformOutput.php +++ b/includes/GlModelTransformOutput.php @@ -46,14 +46,28 @@ class GlModelTransformOutput extends MediaTransformOutput { * @return string HTML */ public function toHtml($options = []) { + $descriptText = $this->file->getDescriptionText(); if ($this->thumb) { - $mainConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'main' ); - $thumbUrl = $mainConfig->get( 'ExtensionAssetsPath' ) . '/GlModelViewer/resources/model_thumb.svg'; - $attrMenuImg = array ( + preg_match('/
([\S\s]*?)<\/pre>/',$descriptText,$modelDescript);
+            $metadata = json_decode($modelDescript[1], true);
+            $poster = $metadata['viewerConfig'][$this->view]['poster'] ?? false;
+
+            if ($poster) {
+                $posterFile = MediaWikiServices::getInstance()->getRepoGroup()->findFile(`File:` . $poster);
+            }
+
+            if ($poster && $posterFile) {
+                $thumbUrl = $posterFile->getFullUrl();
+            } else {
+                $mainConfig = ConfigFactory::getDefaultInstance()->makeConfig( 'main' );
+                $thumbUrl = $mainConfig->get( 'ExtensionAssetsPath' ) . '/GlModelViewer/resources/model_thumb.svg';
+            }
+       
+            $attrThumbImg = array (
                 'src' => $thumbUrl,
-                'style' => 'width: ' . $this->width . 'px; height: ' . $this->height . 'px;'
+                'style' => 'width: ' . $this->width . 'px; height: ' . $this->height . 'px; ' . 'object-fit: contain;'
             );
-            return Html::rawElement('img', $attrMenuImg, '');
+            return Html::rawElement('img', $attrThumbImg, '');
         }
 
         if (isset($options['img-class'])) {
@@ -64,7 +78,7 @@ class GlModelTransformOutput extends MediaTransformOutput {
             $this->parameters['preview'] = $options['preview'];
         }
 
-        return self::buildViewer($this->file->getDescriptionText(),$this->url,$this->parameters);
+        return self::buildViewer($descriptText,$this->url,$this->parameters);
 	}
 
     /**