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);
}
/**