Skip to content

Commit 80abec6

Browse files
JanisPlayerskjnldsv
authored andcommitted
feat: Imaginary WebP support
Signed-off-by: John Molakvoæ <[email protected]>
1 parent 12f57ad commit 80abec6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/private/Preview/Generator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ private function getExtension($mimeType) {
651651
return 'png';
652652
case 'image/jpeg':
653653
return 'jpg';
654+
case 'image/webp':
655+
return 'webp';
654656
case 'image/gif':
655657
return 'gif';
656658
default:

lib/private/Preview/Imaginary.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
106106
$mimeType = 'jpeg';
107107
}
108108

109+
$preview_format = $this->config->getSystemValueString('preview_format', 'jpeg');
110+
111+
switch ($preview_format) { // Change the format to the correct one
112+
case 'webp':
113+
$mimeType = 'webp';
114+
break;
115+
default:
116+
}
117+
109118
$operations = [];
110119

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

124-
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
133+
switch ($mimeType) {
134+
case 'jpeg':
135+
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
136+
break;
137+
case 'webp':
138+
$quality = $this->config->getAppValue('preview', 'webp_quality', '80');
139+
break;
140+
default:
141+
$quality = $this->config->getAppValue('preview', 'jpeg_quality', '80');
142+
}
125143

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

0 commit comments

Comments
 (0)