Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imaginary WebP support #38032

Merged
merged 1 commit into from Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/private/Preview/Generator.php
Expand Up @@ -651,6 +651,8 @@ private function getExtension($mimeType) {
return 'png';
case 'image/jpeg':
return 'jpg';
case 'image/webp':
return 'webp';
case 'image/gif':
return 'gif';
default:
Expand Down
20 changes: 19 additions & 1 deletion lib/private/Preview/Imaginary.php
Expand Up @@ -106,6 +106,15 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
$mimeType = 'jpeg';
}

$preview_format = $this->config->getSystemValueString('preview_format', 'jpeg');

switch ($preview_format) { // Change the format to the correct one
case 'webp':
$mimeType = 'webp';
break;
default:
}

$operations = [];

if ($convert) {
Expand All @@ -121,7 +130,16 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
];
}

$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
switch ($mimeType) {
case 'jpeg':
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
break;
case 'webp':
$quality = $this->config->getAppValue('preview', 'webp_quality', '80');
break;
default:
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
}

$operations[] = [
'operation' => ($crop ? 'smartcrop' : 'fit'),
Expand Down