Add setting for thumbnail scaling
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
Some checks failed
DokuWiki Default Tasks / all (push) Has been cancelled
This commit is contained in:
29
Output.php
29
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;
|
||||
|
||||
Reference in New Issue
Block a user