From f8d5dafc626639606f602561ddb37decfb2a6bd8 Mon Sep 17 00:00:00 2001 From: luxick Date: Tue, 6 Jan 2026 14:23:16 +0100 Subject: [PATCH] Add setting for thumbnail scaling --- Output.php | 29 +++++++++++++++++++++++------ conf/default.php | 4 ++++ conf/metadata.php | 3 +++ lang/de/settings.php | 2 ++ lang/en/settings.php | 2 ++ lang/nl/settings.php | 2 ++ 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/Output.php b/Output.php index 9661d10..2323ee5 100644 --- a/Output.php +++ b/Output.php @@ -58,12 +58,27 @@ class Output $thumbH = 150; $thumbQ = 80; - $placeholderUrl = DOKU_BASE . 'lib/images/blank.gif'; + // Allow generating larger thumbnails (e.g. 2x) while still displaying them + // at 150x150 for sharper results on HiDPI screens. + $thumbScale = 1.0; $syntax = plugin_load('syntax', 'luxtools'); + if ($syntax) { + $rawScale = (string)$syntax->getConf('gallery_thumb_scale'); + if ($rawScale !== '') { + $thumbScale = (float)$rawScale; + } + } + if (!is_finite($thumbScale) || $thumbScale < 1.0) $thumbScale = 1.0; + if ($thumbScale > 4.0) $thumbScale = 4.0; + + $genThumbW = (int)max(1, (int)round($thumbW * $thumbScale)); + $genThumbH = (int)max(1, (int)round($thumbH * $thumbScale)); + + $placeholderUrl = DOKU_BASE . 'lib/images/blank.gif'; $placeholderId = $syntax ? trim((string)$syntax->getConf('thumb_placeholder')) : ''; if ($placeholderId !== '' && function_exists('ml')) { // ml() builds a fetch.php URL for a MediaManager item - $placeholderUrl = ml($placeholderId, ['w' => $thumbW, 'h' => $thumbH], true, '&'); + $placeholderUrl = ml($placeholderId, ['w' => $genThumbW, 'h' => $genThumbH], true, '&'); } /** @var \Doku_Renderer_xhtml $renderer */ @@ -74,8 +89,10 @@ class Output $url = $this->itemWebUrl($item, !empty($params['randlinks'])); $thumbUrl = $this->withQueryParams($url, [ 'thumb' => 1, - 'w' => $thumbW, - 'h' => $thumbH, + 'w' => $genThumbW, + 'h' => $genThumbH, + // Keep quality explicit so cache file naming stays stable. + 'q' => $thumbQ, ]); $safeUrl = hsc($url); $safeThumbUrl = hsc($thumbUrl); @@ -83,8 +100,8 @@ class Output $label = hsc($item['name']); $initialSrc = $safePlaceholderUrl; - $dataThumb = ' data-thumb-src="' . $safeThumbUrl . '"'; - $thumbCachePath = $this->thumbCachePathForItem($item, $thumbW, $thumbH, $thumbQ); + $dataThumb = ' data-thumb-src="' . $safeThumbUrl . '"'; + $thumbCachePath = $this->thumbCachePathForItem($item, $genThumbW, $genThumbH, $thumbQ); if (is_string($thumbCachePath) && $thumbCachePath !== '' && @is_file($thumbCachePath)) { // Thumb already exists: start with it immediately (no JS swap needed) $initialSrc = $safeThumbUrl; diff --git a/conf/default.php b/conf/default.php index 826614c..8d40d92 100644 --- a/conf/default.php +++ b/conf/default.php @@ -12,6 +12,10 @@ $conf['extensions'] = ''; // MediaManager ID for gallery thumbnail placeholder $conf['thumb_placeholder'] = ':wiki:thumb-placeholder.png'; +// Multiplier for gallery thumbnail generation size (1 = 150x150, 2 = 300x300). +// Thumbnails are still displayed as 150x150 on the page. +$conf['gallery_thumb_scale'] = 1; + // Local opener service used by {{open>...}}. $conf['open_service_url'] = 'http://127.0.0.1:8765'; $conf['open_service_token'] = ''; diff --git a/conf/metadata.php b/conf/metadata.php index 479d907..c3f09e2 100644 --- a/conf/metadata.php +++ b/conf/metadata.php @@ -14,5 +14,8 @@ $meta['extensions'] = array('string'); $meta['thumb_placeholder'] = array('string'); +// Thumbnail generation scale factor for the {{images>...}} gallery. +$meta['gallery_thumb_scale'] = array('string'); + $meta['open_service_url'] = array('string'); $meta['open_service_token'] = array('string'); diff --git a/lang/de/settings.php b/lang/de/settings.php index c05e006..382fe98 100644 --- a/lang/de/settings.php +++ b/lang/de/settings.php @@ -4,5 +4,7 @@ $lang['allow_in_comments'] = 'Files-Syntax in Kommentaren erlauben.'; $lang['thumb_placeholder'] = 'MediaManager-ID für den Platzhalter der Galerie-Thumbnails'; +$lang['gallery_thumb_scale'] = 'Skalierungsfaktor für Galerie-Thumbnails. 2 erzeugt schärfere Thumbnails auf HiDPI-Displays (Anzeige bleibt 150×150).'; + $lang['open_service_url'] = 'URL des lokalen Öffner-Dienstes für {{open>...}} (z.B. http://127.0.0.1:8765).'; $lang['open_service_token'] = 'Token für den lokalen Öffner-Dienst (X-Filetools-Token).'; diff --git a/lang/en/settings.php b/lang/en/settings.php index 52398d7..a87722d 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -6,5 +6,7 @@ $lang['extensions'] = 'Comma-separated list of allowed file extensions to list'; $lang['thumb_placeholder'] = 'MediaManager ID for the gallery thumbnail placeholder'; +$lang['gallery_thumb_scale'] = 'Gallery thumbnail scale factor. Use 2 for sharper thumbnails on HiDPI screens (still displayed as 150×150).'; + $lang['open_service_url'] = 'Local opener service URL for the {{open>...}} button (e.g. http://127.0.0.1:8765).'; $lang['open_service_token'] = 'Token sent to the local opener service (X-Filetools-Token).'; diff --git a/lang/nl/settings.php b/lang/nl/settings.php index 480c08d..2c7ec65 100644 --- a/lang/nl/settings.php +++ b/lang/nl/settings.php @@ -10,5 +10,7 @@ $lang['extensions'] = 'Komma-gescheiden lijst van toegestane bestandsextensies v $lang['thumb_placeholder'] = 'MediaManager-ID voor de placeholder van galerij thumbnails'; +$lang['gallery_thumb_scale'] = 'Schaalfactor voor galerij thumbnails. Gebruik 2 voor scherpere thumbnails op HiDPI-schermen (weergave blijft 150×150).'; + $lang['open_service_url'] = 'Lokale opener service-URL voor de {{open>...}} knop (bijv. http://127.0.0.1:8765).'; $lang['open_service_token'] = 'Token dat naar de lokale opener service wordt gestuurd (X-Filetools-Token).';