From 9d6789998377d0d3e1343c3659e9c7fd2a765bf8 Mon Sep 17 00:00:00 2001 From: pk5ls20 Date: Sun, 23 Jun 2024 07:11:40 +0800 Subject: [PATCH] Fix the error where GIF file thumbnails could not be created properly - reference: https://github.com/python-pillow/Pillow/issues/4313 --- app/Services/upload_service.py | 2 +- scripts/local_create_thumbnail.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Services/upload_service.py b/app/Services/upload_service.py index 747b91a..6a83bfe 100644 --- a/app/Services/upload_service.py +++ b/app/Services/upload_service.py @@ -68,7 +68,7 @@ async def _upload_task(self, img_data: ImageData, img_bytes: bytes, skip_ocr: bo logger.info("Start generate and upload thumbnail for {}.", img_data.id) img.thumbnail((256, 256), resample=Image.Resampling.LANCZOS) img_byte_arr = BytesIO() - img.save(img_byte_arr, 'WebP') + img.save(img_byte_arr, 'WebP', save_all=True) await self._storage_service.active_storage.upload(img_byte_arr.getvalue(), thumb_path) logger.success("Thumbnail for {} generated and uploaded!", img_data.id) diff --git a/scripts/local_create_thumbnail.py b/scripts/local_create_thumbnail.py index 0da0f7e..5ad6910 100644 --- a/scripts/local_create_thumbnail.py +++ b/scripts/local_create_thumbnail.py @@ -43,7 +43,7 @@ async def main(): # generate thumbnail max size 256*256 img.thumbnail((256, 256)) img_byte_arr = io.BytesIO() - img.save(img_byte_arr, 'WebP') + img.save(img_byte_arr, 'WebP', save_all=True) await services.storage_service.active_storage.upload(img_byte_arr.getvalue(), f'thumbnails/{str(image_id)}.webp') logger.success("Thumbnail for {} generated!", image_id)