diff --git a/src/Controller/ImageController.php b/src/Controller/ImageController.php index 9149c3d92..9d76de90e 100644 --- a/src/Controller/ImageController.php +++ b/src/Controller/ImageController.php @@ -83,7 +83,6 @@ private function saveAsFile(string $paramString, string $filename): void } $filesystem = new Filesystem(); - $filePath = sprintf('%s%s%s%s%s', $this->getPath('thumbs'), DIRECTORY_SEPARATOR, $paramString, DIRECTORY_SEPARATOR, $filename); $folderMode = $this->config->get('general/filepermissions/folders', 0775); $fileMode = $this->config->get('general/filepermissions/files', 0664); @@ -141,6 +140,7 @@ private function parseParameters(string $paramString): void $this->parameters = [ 'w' => is_numeric($raw[0]) ? (int) $raw[0] : 400, 'h' => ! empty($raw[1]) && is_numeric($raw[1]) ? (int) $raw[1] : 300, + 'fit' => ! empty($raw[2]) ? $this->parseFit($raw[2]) : 'default', ]; foreach ($raw as $rawParameter) { @@ -148,7 +148,7 @@ private function parseParameters(string $paramString): void [$key, $value] = explode('=', $rawParameter); // @todo Add more thumbnailing options here, perhaps. - if (in_array($key, $this->thumbnailOptions, true)) { + if (in_array($key, $this->thumbnailOptions, true) && ! in_array($key, $this->parameters, true)) { $this->parameters[$key] = $value; } } @@ -170,4 +170,28 @@ private function isImage(string $filename): bool return array_key_exists('extension', $pathinfo) && in_array($pathinfo['extension'], $imageExtensions, true); } + + public function parseFit(string $fit): string + { + switch ($fit) { + case 'n': + case 'contain': + case 'default': + return 'contain'; + case 'm': + case 'max': + return 'max'; + case 'f': + case 'fill': + return 'fill'; + case 's': + case 'stretch': + return 'stretch'; + case 'c': + case 'crop': + return 'crop'; + default: + return $fit; + } + } } diff --git a/src/Utils/ThumbnailHelper.php b/src/Utils/ThumbnailHelper.php index 2e1264b92..b0e90967a 100644 --- a/src/Utils/ThumbnailHelper.php +++ b/src/Utils/ThumbnailHelper.php @@ -29,7 +29,7 @@ public function parameters(?int $width = null, ?int $height = null, ?string $loc $paramString = sprintf('%s×%s', $width, $height); if ($fit) { - $paramString .= '×fit=' . $fit; + $paramString .= '×' . $fit; } if ($location && $location !== 'files') {