From 463ab841803b45ea421ad7f9769b836f3000ef8c Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Thu, 9 Feb 2023 02:13:49 -0700 Subject: [PATCH 1/2] Convert 16-bit greyscale to 8-bit when saving as JPEG --- modules/images.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/images.py b/modules/images.py index c2ca8849..c0c68913 100644 --- a/modules/images.py +++ b/modules/images.py @@ -553,6 +553,8 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i elif extension.lower() in (".jpg", ".jpeg", ".webp"): if image_to_save.mode == 'RGBA': image_to_save = image_to_save.convert("RGB") + elif image_to_save.mode == 'I;16': + image_to_save = image_to_save.point(lambda p: p * 0.0038910505836576).convert("L") image_to_save.save(temp_file_path, format=image_format, quality=opts.jpeg_quality) From 73a97cac11456adcda05872364c605ebcd3982ad Mon Sep 17 00:00:00 2001 From: missionfloyd Date: Thu, 9 Feb 2023 17:04:55 -0700 Subject: [PATCH 2/2] Use RGB for webp Doesn't support greyscale (L) --- modules/images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/images.py b/modules/images.py index c0c68913..b335502b 100644 --- a/modules/images.py +++ b/modules/images.py @@ -554,7 +554,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i if image_to_save.mode == 'RGBA': image_to_save = image_to_save.convert("RGB") elif image_to_save.mode == 'I;16': - image_to_save = image_to_save.point(lambda p: p * 0.0038910505836576).convert("L") + image_to_save = image_to_save.point(lambda p: p * 0.0038910505836576).convert("RGB" if extension.lower() == ".webp" else "L") image_to_save.save(temp_file_path, format=image_format, quality=opts.jpeg_quality)