@@ -13,7 +13,7 @@ class BasicFormatter
1313{
1414 /** @var Options */
1515 protected $ options ;
16- /** @var \Doku_Renderer */
16+ /** @var \Doku_Renderer */
1717 protected $ renderer ;
1818
1919 /**
@@ -74,23 +74,39 @@ protected function renderImage(Image $image)
7474
7575 /**
7676 * Calculate the thumbnail size
77+ *
78+ * @param Image $image
79+ * @param int|float $retina The retina scaling factor
80+ * @return array
7781 */
78- protected function getThumbnailSize (Image $ image )
82+ protected function getThumbnailSize (Image $ image, $ retina = 1 )
7983 {
80- $ crop = $ this ->options ->crop ;
84+ $ thumbW = $ this ->options ->thumbnailWidth * $ retina ;
85+ $ thumbH = $ this ->options ->thumbnailHeight * $ retina ;
86+
87+ // if image size is unknown, use the configured thumbnail size
8188 if (!$ image ->getWidth () || !$ image ->getHeight ()) {
82- $ crop = true ;
89+ return [ $ thumbW , $ thumbH ] ;
8390 }
84- if (!$ crop ) {
91+
92+ // avoid upscaling
93+ if (
94+ $ image ->getWidth () < $ thumbW &&
95+ $ image ->getHeight () < $ thumbH
96+ ) {
97+ return [$ image ->getWidth (), $ image ->getHeight ()];
98+ }
99+
100+ if (!$ this ->options ->crop ) {
85101 [$ thumbWidth , $ thumbHeight ] = $ this ->fitBoundingBox (
86102 $ image ->getWidth (),
87103 $ image ->getHeight (),
88- $ this -> options -> thumbnailWidth ,
89- $ this -> options -> thumbnailHeight
104+ $ thumbW ,
105+ $ thumbH
90106 );
91107 } else {
92- $ thumbWidth = $ this -> options -> thumbnailWidth ;
93- $ thumbHeight = $ this -> options -> thumbnailHeight ;
108+ $ thumbWidth = $ thumbW ;
109+ $ thumbHeight = $ thumbH ;
94110 }
95111 return [$ thumbWidth , $ thumbHeight ];
96112 }
0 commit comments