webPath = $webPath; $this->cache = initializeCache(); } public function isImageViewable($extension) { global $config; if (empty($extension) || trim($extension) === '') { return false; } $extension = strtolower($extension); if (!in_array($extension, $this->allowedImageExtensions)) { return false; } $settingKey = getExtensionSetting($extension, 'viewing'); if ($settingKey !== null) { return isset($config['viewable_files'][$settingKey]) ? $config['viewable_files'][$settingKey] : false; } return false; } public function renderImageViewer($fullPath, $filename, $extension, $currentPath, $viewMode = 'default') { global $router, $config; $pathParts = explode('/', trim($currentPath, '/')); $lastPart = end($pathParts); if ($lastPart === $filename) { array_pop($pathParts); $currentPath = implode('/', $pathParts); } $relativePath = $currentPath ? $currentPath . '/' . $filename : $filename; if ($this->cache->hasValidFile($fullPath, 'imageview_' . $viewMode)) { echo $this->cache->getFile($fullPath, 'imageview_' . $viewMode); exit; } ob_start(); $this->serveImageView($fullPath, $filename, $extension, $currentPath, $viewMode); $output = ob_get_clean(); $this->cache->setFile($fullPath, $output, 'imageview_' . $viewMode); echo $output; exit; } private function serveImageView($fullPath, $filename, $extension, $currentPath, $viewMode = 'default') { global $router, $config; $disableRawImageViewing = isset($config['main']['disable_raw_image_conversion']) ? $config['main']['disable_raw_image_conversion'] : true; $maxResolution = isset($config['main']['max_image_resolution']) ? $config['main']['max_image_resolution'] : '1920x1080'; list($maxWidth, $maxHeight) = explode('x', $maxResolution); $maxWidth = (int)$maxWidth; $maxHeight = (int)$maxHeight; $fileSize = filesize($fullPath); $fileSizeFormatted = $this->formatBytes($fileSize); $fileModified = date('Y-m-d H:i:s', filemtime($fullPath)); $dimensions = $this->getImageDimensions($fullPath, $extension); $originalDimensionText = $dimensions ? $dimensions['width'] . ' × ' . $dimensions['height'] . ' px' : 'Unknown'; $exceedsResolution = false; if ($dimensions && ($dimensions['width'] > $maxWidth || $dimensions['height'] > $maxHeight)) { $exceedsResolution = true; } $isTrueScale = ($viewMode === 'truescale'); $isSvgTrueScale = ($extension === 'svg' && $isTrueScale); $needsSpecialHandling = in_array($extension, [ 'tiff', 'psd', 'heic', 'cr2', 'cr3', 'nef', 'nrw', 'arw', 'raf', 'rw2', 'orf', 'pef', 'dng', '3fr', 'x3f', 'ai', 'fig', 'sketch', 'xcf' ]); $downloadUrl = $router->generateFileURL($currentPath, $filename, 'download'); $viewUrl = $router->generateFileURL($currentPath, $filename, 'view', 'default'); $originalRawUrl = $router->generateFileURL($currentPath, $filename, 'view', 'raw'); $trueScaleUrl = $viewUrl . '&scale=true'; $imageDisplayUrl = $originalRawUrl; $currentFullUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $backUrl = preg_replace('/\/[^\/]+\/\?.*$/', '/', $currentFullUrl); if (!preg_match('/\?/', $currentFullUrl)) { $backUrl = preg_replace('/\/[^\/]+\/$/', '/', $currentFullUrl); } $securityStatus = getSecurityStatus(); $lockIcon = $securityStatus['secure'] ? $this->webPath . '/.indexer_files/icons/app/green.png' : $this->webPath . '/.indexer_files/icons/app/red.png'; $convertedDimensions = null; $dimensionText = $originalDimensionText; if ($disableRawImageViewing && $needsSpecialHandling) { $showError = true; $errorMessage = "Raw image viewing is disabled on this server.
Please download the file to view it."; } else { $showError = false; $errorMessage = ''; if (($exceedsResolution && !$isTrueScale) || $needsSpecialHandling) { $conversionResult = $this->attemptImageConversion($fullPath, $extension, $maxWidth, $maxHeight); if ($conversionResult) { $imageDisplayUrl = $conversionResult['data']; $convertedDimensions = $conversionResult['dimensions']; if ($convertedDimensions) { $dimensionText = $originalDimensionText . ' (converted: ' . $convertedDimensions['width'] . ' × ' . $convertedDimensions['height'] . ' px)'; } } elseif ($needsSpecialHandling) { $showError = true; $errorMessage = "This image format (" . strtoupper($extension) . ") requires special server extensions to display.
Please download the file or view raw to see the image."; } } } ?> <?php echo $filename; ?>
<?php echo $securityStatus['secure'] ? 'Secure' : 'Not Secure'; ?>
Raw View
<?php echo htmlspecialchars($filename); ?> <?php echo htmlspecialchars($filename); ?>
Filename:
Type:
Image
Dimensions:
File Size:
Modified:
← Back to Folder Fit to Screen View True Scale Open Raw Download
cache->hasValidImage($fullPath, $maxWidth, $maxHeight)) { $cachedData = $this->cache->getImageDataUri($fullPath, $maxWidth, $maxHeight); if ($cachedData) { return [ 'data' => $cachedData, 'dimensions' => $this->getCachedImageDimensions($fullPath, $maxWidth, $maxHeight) ]; } } if (extension_loaded('imagick')) { try { $imagick = new Imagick($fullPath); $width = $imagick->getImageWidth(); $height = $imagick->getImageHeight(); $newWidth = $width; $newHeight = $height; if ($width > $maxWidth || $height > $maxHeight) { $ratio = min($maxWidth / $width, $maxHeight / $height); $newWidth = (int)($width * $ratio); $newHeight = (int)($height * $ratio); $imagick->thumbnailImage($newWidth, $newHeight, true); } $imagick->setImageFormat('png'); $imageBlob = $imagick->getImageBlob(); $imagick->clear(); $this->cache->setImage($fullPath, $imageBlob, $maxWidth, $maxHeight); return [ 'data' => 'data:image/png;base64,' . base64_encode($imageBlob), 'dimensions' => [ 'width' => $newWidth, 'height' => $newHeight ] ]; } catch (Exception $e) { } } if (function_exists('imagecreatefromstring')) { $imageData = @file_get_contents($fullPath); if ($imageData !== false) { $image = @imagecreatefromstring($imageData); if ($image !== false) { $width = imagesx($image); $height = imagesy($image); $newWidth = $width; $newHeight = $height; if ($width > $maxWidth || $height > $maxHeight) { $ratio = min($maxWidth / $width, $maxHeight / $height); $newWidth = (int)($width * $ratio); $newHeight = (int)($height * $ratio); $resized = imagecreatetruecolor($newWidth, $newHeight); imagealphablending($resized, false); imagesavealpha($resized, true); imagecopyresampled($resized, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); imagedestroy($image); $image = $resized; } ob_start(); imagepng($image); $pngData = ob_get_clean(); imagedestroy($image); $this->cache->setImage($fullPath, $pngData, $maxWidth, $maxHeight); return [ 'data' => 'data:image/png;base64,' . base64_encode($pngData), 'dimensions' => [ 'width' => $newWidth, 'height' => $newHeight ] ]; } } } return false; } private function getCachedImageDimensions($fullPath, $maxWidth, $maxHeight) { $originalDims = $this->getImageDimensions($fullPath, pathinfo($fullPath, PATHINFO_EXTENSION)); if ($originalDims) { $width = $originalDims['width']; $height = $originalDims['height']; if ($width > $maxWidth || $height > $maxHeight) { $ratio = min($maxWidth / $width, $maxHeight / $height); return [ 'width' => (int)($width * $ratio), 'height' => (int)($height * $ratio) ]; } return $originalDims; } return null; } private function getImageDimensions($fullPath, $extension) { $extension = strtolower($extension); if ($extension === 'gif') { if (extension_loaded('imagick')) { try { $imagick = new Imagick($fullPath); $imagick->setIteratorIndex(0); $width = $imagick->getImageWidth(); $height = $imagick->getImageHeight(); $imagick->clear(); return [ 'width' => $width, 'height' => $height ]; } catch (Exception $e) { } } if (function_exists('imagecreatefromgif')) { $image = @imagecreatefromgif($fullPath); if ($image !== false) { $width = imagesx($image); $height = imagesy($image); imagedestroy($image); return [ 'width' => $width, 'height' => $height ]; } } } if (extension_loaded('imagick')) { try { $imagick = new Imagick($fullPath); $width = $imagick->getImageWidth(); $height = $imagick->getImageHeight(); $imagick->clear(); return [ 'width' => $width, 'height' => $height ]; } catch (Exception $e) { } } $getimagesizeFormats = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp', 'ico', 'tiff', 'jfif']; if (in_array($extension, $getimagesizeFormats)) { $imageInfo = @getimagesize($fullPath); if ($imageInfo !== false) { return [ 'width' => $imageInfo[0], 'height' => $imageInfo[1] ]; } } if ($extension === 'svg') { $svgContent = @file_get_contents($fullPath); if ($svgContent !== false) { if (preg_match('/width=["\'](\d+(?:\.\d+)?)["\']/', $svgContent, $widthMatch) && preg_match('/height=["\'](\d+(?:\.\d+)?)["\']/', $svgContent, $heightMatch)) { return [ 'width' => (int)$widthMatch[1], 'height' => (int)$heightMatch[1] ]; } if (preg_match('/viewBox=["\'][\d\s]+\s+(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)["\']/', $svgContent, $viewBoxMatch)) { return [ 'width' => (int)$viewBoxMatch[1], 'height' => (int)$viewBoxMatch[2] ]; } } } if ($extension === 'avif' && function_exists('exif_read_data')) { $exifData = @exif_read_data($fullPath); if ($exifData !== false && isset($exifData['COMPUTED']['Width']) && isset($exifData['COMPUTED']['Height'])) { return [ 'width' => $exifData['COMPUTED']['Width'], 'height' => $exifData['COMPUTED']['Height'] ]; } } if (function_exists('imagecreatefromstring')) { $imageData = @file_get_contents($fullPath); if ($imageData !== false) { $image = @imagecreatefromstring($imageData); if ($image !== false) { $width = imagesx($image); $height = imagesy($image); imagedestroy($image); return [ 'width' => $width, 'height' => $height ]; } } } return null; } private function formatBytes($size) { if ($size === null) return '-'; $units = ['B', 'KB', 'MB', 'GB']; for ($i = 0; $size > 1024 && $i < count($units) - 1; $i++) { $size /= 1024; } return round($size, 2) . ' ' . $units[$i]; } } ?>