Always create thumbnails using WebP
authorAlexander Ebert <ebert@woltlab.com>
Sat, 13 Apr 2024 16:59:26 +0000 (18:59 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 8 Jun 2024 10:19:38 +0000 (12:19 +0200)
wcfsetup/install/files/lib/system/file/processor/FileProcessor.class.php

index 3088e94787ffa4ae772086531949930e2097cc5f..54431683770d0426ceb84d39099676689cd0dff0 100644 (file)
@@ -103,14 +103,11 @@ final class FileProcessor extends SingletonFactory
                 $imageAdapter->loadFile($file->getPath() . $file->getSourceFilename());
             }
 
-            // TODO: Thumbnails are currently created using the exact same file
-            //       type as the source file. It may make more sense to always
-            //       use an efficient format, like WebP, exclusively.
-            assert($imageAdapter instanceof ImageAdapter);
+            \assert($imageAdapter instanceof ImageAdapter);
             $image = $imageAdapter->createThumbnail($format->width, $format->height, $format->retainDimensions);
 
-            $filename = FileUtil::getTemporaryFilename();
-            $imageAdapter->writeImage($image, $filename);
+            $filename = FileUtil::getTemporaryFilename(extension: 'webp');
+            $imageAdapter->saveImageAs($image, $filename, 'webp', 80);
 
             $fileThumbnail = FileThumbnailEditor::createFromTemporaryFile($file, $format, $filename);
             $processor->adoptThumbnail($fileThumbnail);