From 3d2dbefcde4091ce4e6d915b3eda16ca964097f2 Mon Sep 17 00:00:00 2001 From: Andray Date: Thu, 11 Jul 2024 23:54:25 +0400 Subject: [PATCH] fix OSError: cannot write mode P as JPEG --- modules/api/api.py | 2 +- modules/shared_state.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/api/api.py b/modules/api/api.py index 307476bdd..97ec7514e 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -113,7 +113,7 @@ def encode_pil_to_base64(image): image.save(output_bytes, format="PNG", pnginfo=(metadata if use_metadata else None), quality=opts.jpeg_quality) elif opts.samples_format.lower() in ("jpg", "jpeg", "webp"): - if image.mode == "RGBA": + if image.mode in ("RGBA", "P"): image = image.convert("RGB") parameters = image.info.get('parameters', None) exif_bytes = piexif.dump({ diff --git a/modules/shared_state.py b/modules/shared_state.py index f74eafc58..4cd53af62 100644 --- a/modules/shared_state.py +++ b/modules/shared_state.py @@ -162,7 +162,7 @@ class State: errors.record_exception() def assign_current_image(self, image): - if shared.opts.live_previews_image_format == 'jpeg' and image.mode == 'RGBA': + if shared.opts.live_previews_image_format == 'jpeg' and image.mode in ('RGBA', 'P'): image = image.convert('RGB') self.current_image = image self.id_live_preview += 1